setwd("")
library(foreign)
library(memisc)

# INSTRUCTIONS -----------------------------------------------------------------
# NOTE: This program is very long and it is possible to introduce errors
#       when adding new variables. To avoid this, one should follow these
#       instructions.
# 1)   To add a new variable, first add its name to the masterlist list below.
#       This will allow it to be among the columns selected for before the
#       files are merged.
#
# 2)   Next, add lines below each file in order to assign the variable the
#       correct values from the survey. This is dependent upon which questions
#       correspond to the data that is needed.
#
# 3)   Although questions might have a certain case in the survey data, the
#       case you need to use is dependent upon which function is being used to
#       read the data in. If the function is read.csv.upper() or read.por.upper()
#       use uppercase (eg. Q4A instead of q4a). If read.csv.lower() or
#       read.por.lower() is used, use lowercase (eg. state instead of STATE). If
#       a .fwf, .Rdata, or another filetype is being used, adhere to whatever
#       looks right.
#
# 4)   It is likely that the question(s) of interest to you were not asked in
#       every iteration of the Kaiser surveys. You do not need to add code for
#       surveys that do ask your question(s). The subsetn() function will
#       autmoatically add a column filled with NA for any names in masterlist
#       that are not explicitally added by the programmer.
# ---------------------------------------------------------------------------

masterlist <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE", "REGISTERED", "PID5", "VOTED")

# custom read and subsetting functions ---------------------------------------------------

read.csv.upper <- function(filename) {
  temp <- read.csv(filename)
  names(temp) <- toupper(names(temp))
  names(temp)[[1]] <- "PSRAID"
  temp
}
read.por.upper <- function(filename, to.data.frame) {
  temp <- read.spss(filename, to.data.frame=T)
  names(temp) <- toupper(names(temp))
  temp
}
read.csv.lower <- function(filename) {
  temp <- read.csv(filename)
  names(temp) <- tolower(names(temp))
  names(temp)[[1]] <- "psraid"
  temp
}
read.por.lower <- function(filename, to.data.frame) {
  temp <- read.spss(filename, to.data.frame=T)
  names(temp) <- tolower(names(temp))
  temp
}

subsetn <- function(x, subset, select) {
  probs <- setdiff(masterlist, names(x))
  for(p in probs) {
    x[[toString(p)]] <- NA
  }
  x[select]
}

getPID5metric <- function(survey) {
  c(sum(grepl(1, survey)), sum(grepl(2, survey)), sum(grepl(3, survey)), sum(grepl(4, survey)), sum(grepl(5, survey)))
}

# column name and data normalization --------------------------------------

#### september 2017
dta165 <- read.por.upper("hni165.por",to.data.frame=T)
#dta165 <- read.por.upper("hni165.por",to.data.frame=T)

dta165$INCOME2 <- NA
dta165$INCOME2[dta165$INCOME=="Less than $20,000"] <- 10
dta165$INCOME2[dta165$INCOME=="$20,000 to less than $30,000"] <- 25
dta165$INCOME2[dta165$INCOME=="$30,000 to less than $40,000"] <- 35
dta165$INCOME2[dta165$INCOME=="$40,000 to less than $50,000"] <- 45
dta165$INCOME2[dta165$INCOME=="$50,000 to less than $75,000"] <- 62.5
dta165$INCOME2[dta165$INCOME=="$75,000 to less than $90,000"] <- 82.5
dta165$INCOME2[dta165$INCOME=="$90,000 to less than $100,000"] <- 95
dta165$INCOME2[dta165$INCOME=="$100,000 or more"] <- 200

dta165$INCOME <- dta165$INCOME2

dta165$HISP <- 0
dta165$HISP[dta165$HISPANIC=="Yes"] <- 1

dta165$EDUC2 <- NA
dta165$EDUC2[dta165$EDUC=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta165$EDUC2[dta165$EDUC=="High school incomplete (Grades 9-11 or Grade 12 with no diploma)"] <- 10
dta165$EDUC2[dta165$EDUC=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta165$EDUC2[dta165$EDUC=="Some college, no degree (includes some community college)"] <- 13
dta165$EDUC2[dta165$EDUC=="Two year associate degree from a college or university"] <- 14
dta165$EDUC2[dta165$EDUC=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta165$EDUC2[dta165$EDUC=="Some postgraduate or professional school, no postgraduate degree"] <- 17
dta165$EDUC2[dta165$EDUC=="Post-graduate or professional degree, including master's, doctorate, medical, or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta165$EDUC <- dta165$EDUC2

dta165$PID <- NA
dta165$PID[dta165$PARTY=="Democrat"] <- 1
dta165$PID[dta165$PARTY %in% c("Independent","Or what?")] <- 2
dta165$PID[dta165$PARTY=="Republican"] <- 3

dta165$BETPER <- NA

dta165$BETCOU <- NA

dta165$REGISTERED <- NA

# NOTE: var replaced with FAVOR var.
dta165$SUPPORT <- NA
#dta165$SUPPORT[dta165$Q1=="Strongly support"] <- 4
#dta165$SUPPORT[dta165$Q1=="Somewhat support"] <- 3
#dta165$SUPPORT[dta165$Q1=="Somewhat oppose"] <- 2
#dta165$SUPPORT[dta165$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta165$BLACK <- (dta165$RACE=="Black or African-American")*1
dta165$ASIAN <- (dta165$RACE=="Asian")*1
dta165$OTHER <- (dta165$RACE=="Other or mixed race")*1

dta165$AGE <- as.numeric(as.character(dta165$AGE))
dta165$MEDICARE <- (dta165$AGE > 64)*1

dta165$COVERED <- (dta165$COVERAGE=="Covered by health insurance")*1

dta165$IDEO <- NA
dta165$IDEO[dta165$IDEOLOGY=="Liberal"] <- 3
dta165$IDEO[dta165$IDEOLOGY=="Moderate"] <- 2
dta165$IDEO[dta165$IDEOLOGY=="Conservative"] <- 1

dta165$FAVOR <- NA
dta165$FAVOR[dta165$ACA=="Very favorable"] <- 4
dta165$FAVOR[dta165$ACA=="Somewhat favorable"] <- 3
dta165$FAVOR[dta165$ACA=="Somewhat unfavorable"] <- 2
dta165$FAVOR[dta165$ACA=="Very unfavorable"] <- 1

# Question Still Not Asked
dta165$SELFEMPLOY <- NA
#dta165$SELFEMPLOY[dta165$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta165$RETIRED <- 0
dta165$RETIRED[dta165$EMPLOY=="Retired"] <- 1

dta165$MEDICARESR <- 0
dta165$MEDICARESR <- 1*(dta165$COVTYPE=="Medicare")
dta165$MEDICARESR[dta165$COVTYPE %in% c(NA)] <- 0

dta165$MEDICAID <- 0
dta165$MEDICAID <- 1*(dta165$COVTYPE=="MEDICAID")
dta165$MEDICAID[dta165$COVTYPE %in% c(NA)] <- 0

dta165$HEALTH2 <- NA
dta165$HEALTH2[dta165$HEALTH=="Excellent"] <- 5
dta165$HEALTH2[dta165$HEALTH=="Very good"] <- 4
dta165$HEALTH2[dta165$HEALTH=="Good"] <- 3
dta165$HEALTH2[dta165$HEALTH=="Only fair"] <- 2
dta165$HEALTH2[dta165$HEALTH=="Poor"] <- 1

dta165$HEALTH <- dta165$HEALTH2

dta165$SAWAD <- NA
dta165$SAWADPOS <- NA
dta165$SAWADNEG <- NA
dta165$SAWADBOTH <- NA

#dta165$STATE <- dta165$state
#dta165$SSTATE #<- dta165$STATE

dta165$MALE <- 1*(dta165$RSEX=="Male")

dta165$NUMBER <- 165

dta165$MONTH <- 104

dta165$MARKET <- 0
dta165$MARKET[dta165$COVSELF=="From (healthcare.gov or STATE SPECIFIC MARKETPLACE NAME)"]<-1

dta165$SELFINSURE <- 0
dta165$SELFINSURE[dta165$COVTYPE=="Plan you purchased yourself"]<-1

dta165$EMPLINSURE <- 0
dta165$EMPLINSURE[dta165$COVTYPE=="Plan through your employer"]<-1
dta165$EMPLINSURE[dta165$COVTYPE=="Plan through your spouse's employer"]<-1

#dta165$PREEXIST <- 1*(dta165$PREX=="Yes, someone in household has pre-existing #condition")
dta165$PREEXIST <- NA

dta165$HURT <- NA

dta165$HELPHOW <- NA

dta165$HURTHOW <- NA
dta165$PID5 <- NA
dta165$VOTED <- NA

#dim(s160)


dta165$PSRAID <- dta165$ID
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE", "REGISTERED")
s165 <- subsetn(dta165,select=masterlist, subset=T)

#### august 2017

#dta164 <- read.por.upper("hni164-august.por",to.data.frame=T)
dta164 <- read.por.upper("hni164.por",to.data.frame=T)

dta164$INCOME2 <- NA
dta164$INCOME2[dta164$INCOME=="Less than $20,000"] <- 10
dta164$INCOME2[dta164$INCOME=="$20,000 to less than $30,000"] <- 25
dta164$INCOME2[dta164$INCOME=="$30,000 to less than $40,000"] <- 35
dta164$INCOME2[dta164$INCOME=="$40,000 to less than $50,000"] <- 45
dta164$INCOME2[dta164$INCOME=="$50,000 to less than $75,000"] <- 62.5
dta164$INCOME2[dta164$INCOME=="$75,000 to less than $90,000"] <- 82.5
dta164$INCOME2[dta164$INCOME=="$90,000 to less than $100,000"] <- 95
dta164$INCOME2[dta164$INCOME=="$100,000 or more"] <- 200

dta164$INCOME <- dta164$INCOME2

dta164$HISP <- 0
dta164$HISP[dta164$HISPANIC=="Yes"] <- 1

dta164$EDUC2 <- NA
dta164$EDUC2[dta164$EDUC=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta164$EDUC2[dta164$EDUC=="High school incomplete (Grades 9-11 or Grade 12 with no diploma)"] <- 10
dta164$EDUC2[dta164$EDUC=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta164$EDUC2[dta164$EDUC=="Some college, no degree (includes some community college)"] <- 13
dta164$EDUC2[dta164$EDUC=="Two year associate degree from a college or university"] <- 14
dta164$EDUC2[dta164$EDUC=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta164$EDUC2[dta164$EDUC=="Some postgraduate or professional school, no postgraduate degree"] <- 17
dta164$EDUC2[dta164$EDUC=="Post-graduate or professional degree, including master's, doctorate, medical, or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta164$EDUC <- dta164$EDUC2

dta164$PID <- NA
dta164$PID[dta164$PARTY=="Democrat"] <- 1
dta164$PID[dta164$PARTY %in% c("Independent","Or what?")] <- 2
dta164$PID[dta164$PARTY=="Republican"] <- 3

dta164$PID5 <- NA
dta164$PID5[dta164$PID==1] <- 1
dta164$PID5[dta164$PARTYLEA=="Democratic"] <- 2
dta164$PID5[dta164$PARTYLEA %in% c("Independent/don't lean to either party (VOL.)", "Other party (VOL).", "Don't Know", "Refused")] <- 3
dta164$PID5[dta164$PARTYLEA=="Republican"] <- 4
dta164$PID5[dta164$PID==3] <- 5

dta164$BETPER <- NA

dta164$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta164$SUPPORT <- NA
#dta164$SUPPORT[dta164$Q1=="Strongly support"] <- 4
#dta164$SUPPORT[dta164$Q1=="Somewhat support"] <- 3
#dta164$SUPPORT[dta164$Q1=="Somewhat oppose"] <- 2
#dta164$SUPPORT[dta164$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta164$BLACK <- (dta164$RACE=="Black or African-American")*1
dta164$ASIAN <- (dta164$RACE=="Asian")*1
dta164$OTHER <- (dta164$RACE=="Other or mixed race")*1

dta164$AGE <- as.numeric(as.character(dta164$AGE))
dta164$MEDICARE <- (dta164$AGE > 64)*1

dta164$COVERED <- (dta164$COVERAGE=="Covered by health insurance")*1

dta164$IDEO <- NA
dta164$IDEO[dta164$IDEOLOGY=="Liberal"] <- 3
dta164$IDEO[dta164$IDEOLOGY=="Moderate"] <- 2
dta164$IDEO[dta164$IDEOLOGY=="Conservative"] <- 1

dta164$FAVOR <- NA
dta164$FAVOR[dta164$ACA=="Very favorable"] <- 4
dta164$FAVOR[dta164$ACA=="Somewhat favorable"] <- 3
dta164$FAVOR[dta164$ACA=="Somewhat unfavorable"] <- 2
dta164$FAVOR[dta164$ACA=="Very unfavorable"] <- 1

# Question Still Not Asked
dta164$SELFEMPLOY <- NA
#dta164$SELFEMPLOY[dta164$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta164$RETIRED <- 0
dta164$RETIRED[dta164$EMPLOY=="Retired"] <- 1

dta164$MEDICARESR <- 0
dta164$MEDICARESR <- 1*(dta164$COVTYPE=="Medicare")
dta164$MEDICARESR[dta164$COVTYPE %in% c(NA)] <- 0

dta164$MEDICAID <- 0
dta164$MEDICAID <- 1*(dta164$COVTYPE=="MEDICAID")
dta164$MEDICAID[dta164$COVTYPE %in% c(NA)] <- 0

dta164$HEALTH2 <- NA
dta164$HEALTH2[dta164$HEALTH=="Excellent"] <- 5
dta164$HEALTH2[dta164$HEALTH=="Very good"] <- 4
dta164$HEALTH2[dta164$HEALTH=="Good"] <- 3
dta164$HEALTH2[dta164$HEALTH=="Only fair"] <- 2
dta164$HEALTH2[dta164$HEALTH=="Poor"] <- 1

dta164$HEALTH <- dta164$HEALTH2

dta164$SAWAD <- NA
dta164$SAWADPOS <- NA
dta164$SAWADNEG <- NA
dta164$SAWADBOTH <- NA

#dta164$STATE <- dta164$state
#dta164$SSTATE #<- dta164$STATE

dta164$MALE <- 1*(dta164$RSEX=="Male")

dta164$NUMBER <- 164

dta164$MONTH <- 103

dta164$MARKET <- 0
dta164$MARKET[dta164$COVSELF=="From (healthcare.gov or STATE SPECIFIC MARKETPLACE NAME)"]<-1

dta164$SELFINSURE <- 0
dta164$SELFINSURE[dta164$COVTYPE=="Plan you purchased yourself"]<-1

dta164$EMPLINSURE <- 0
dta164$EMPLINSURE[dta164$COVTYPE=="Plan through your employer"]<-1
dta164$EMPLINSURE[dta164$COVTYPE=="Plan through your spouse's employer"]<-1

#dta164$PREEXIST <- 1*(dta164$PREX=="Yes, someone in household has pre-existing #condition")
dta164$PREEXIST <- NA

dta164$HURT <- NA

dta164$HELPHOW <- NA

dta164$HURTHOW <- NA

dta164$PSRAID <- dta164$ID
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE", "REGISTERED")
s164 <- subsetn(dta164,select=masterlist, subset=T)




#### July 2017

dta163 <- read.por.upper("hni163.por",to.data.frame=T)

dta163$INCOME2 <- NA
dta163$INCOME2[dta163$INCOME=="Less than $20,000"] <- 10
dta163$INCOME2[dta163$INCOME=="$20,000 to less than $30,000"] <- 25
dta163$INCOME2[dta163$INCOME=="$30,000 to less than $40,000"] <- 35
dta163$INCOME2[dta163$INCOME=="$40,000 to less than $50,000"] <- 45
dta163$INCOME2[dta163$INCOME=="$50,000 to less than $75,000"] <- 62.5
dta163$INCOME2[dta163$INCOME=="$75,000 to less than $90,000"] <- 82.5
dta163$INCOME2[dta163$INCOME=="$90,000 to less than $100,000"] <- 95
dta163$INCOME2[dta163$INCOME=="$100,000 or more"] <- 200

dta163$INCOME <- dta163$INCOME2

dta163$HISP <- 0
dta163$HISP[dta163$HISPANIC=="Yes"] <- 1

dta163$EDUC2 <- NA
dta163$EDUC2[dta163$EDUC=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta163$EDUC2[dta163$EDUC=="High school incomplete (Grades 9-11 or Grade 12 with no diploma)"] <- 10
dta163$EDUC2[dta163$EDUC=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta163$EDUC2[dta163$EDUC=="Some college, no degree (includes some community college)"] <- 13
dta163$EDUC2[dta163$EDUC=="Two year associate degree from a college or university"] <- 14
dta163$EDUC2[dta163$EDUC=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta163$EDUC2[dta163$EDUC=="Some postgraduate or professional school, no postgraduate degree"] <- 17
dta163$EDUC2[dta163$EDUC=="Post-graduate or professional degree, including master's, doctorate, medical, or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta163$EDUC <- dta163$EDUC2

dta163$PID <- NA
dta163$PID[dta163$PARTY=="Democrat"] <- 1
dta163$PID[dta163$PARTY %in% c("Independent","Or what?")] <- 2
dta163$PID[dta163$PARTY=="Republican"] <- 3

dta163$PID5 <- NA
dta163$PID5[dta163$PID==1] <- 1
dta163$PID5[dta163$PARTYLEA=="Democratic"] <- 2
dta163$PID5[dta163$PARTYLEA %in% c("Independent/don't lean to either party (VOL.)", "Other party (VOL).", "Don't Know", "Refused")] <- 3
dta163$PID5[dta163$PARTYLEA=="Republican"] <- 4
dta163$PID5[dta163$PID==3] <- 5

dta163$BETPER <- NA

dta163$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta163$SUPPORT <- NA
#dta163$SUPPORT[dta163$Q1=="Strongly support"] <- 4
#dta163$SUPPORT[dta163$Q1=="Somewhat support"] <- 3
#dta163$SUPPORT[dta163$Q1=="Somewhat oppose"] <- 2
#dta163$SUPPORT[dta163$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta163$BLACK <- (dta163$RACE=="Black or African-American")*1
dta163$ASIAN <- (dta163$RACE=="Asian")*1
dta163$OTHER <- (dta163$RACE=="Other or mixed race")*1

dta163$AGE <- as.numeric(as.character(dta163$AGE))
dta163$MEDICARE <- (dta163$AGE > 64)*1

dta163$COVERED <- (dta163$COVERAGE=="Covered by health insurance")*1

dta163$IDEO <- NA
dta163$IDEO[dta163$IDEOLOGY=="Liberal"] <- 3
dta163$IDEO[dta163$IDEOLOGY=="Moderate"] <- 2
dta163$IDEO[dta163$IDEOLOGY=="Conservative"] <- 1

dta163$FAVOR <- NA
dta163$FAVOR[dta163$ACA=="Very favorable"] <- 4
dta163$FAVOR[dta163$ACA=="Somewhat favorable"] <- 3
dta163$FAVOR[dta163$ACA=="Somewhat unfavorable"] <- 2
dta163$FAVOR[dta163$ACA=="Very unfavorable"] <- 1

# Question Still Not Asked
dta163$SELFEMPLOY <- NA
#dta163$SELFEMPLOY[dta163$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta163$RETIRED <- 0
dta163$RETIRED[dta163$EMPLOY=="Retired"] <- 1

dta163$MEDICARESR <- 0
dta163$MEDICARESR <- 1*(dta163$COVTYPE=="Medicare")
dta163$MEDICARESR[dta163$COVTYPE %in% c(NA)] <- 0

dta163$MEDICAID <- 0
dta163$MEDICAID <- 1*(dta163$COVTYPE=="MEDICAID")
dta163$MEDICAID[dta163$COVTYPE %in% c(NA)] <- 0

dta163$HEALTH2 <- NA
dta163$HEALTH2[dta163$HEALTH=="Excellent"] <- 5
dta163$HEALTH2[dta163$HEALTH=="Very good"] <- 4
dta163$HEALTH2[dta163$HEALTH=="Good"] <- 3
dta163$HEALTH2[dta163$HEALTH=="Only fair"] <- 2
dta163$HEALTH2[dta163$HEALTH=="Poor"] <- 1

dta163$HEALTH <- dta163$HEALTH2

dta163$SAWAD <- NA
dta163$SAWADPOS <- NA
dta163$SAWADNEG <- NA
dta163$SAWADBOTH <- NA

#dta163$STATE <- dta163$state
#dta163$SSTATE #<- dta163$STATE

dta163$MALE <- 1*(dta163$RSEX=="Male")

dta163$NUMBER <- 163

dta163$MONTH <- 102

dta163$MARKET <- 0
dta163$MARKET[dta163$COVSELF=="From (healthcare.gov or STATE SPECIFIC MARKETPLACE NAME)"]<-1

dta163$SELFINSURE <- 0
dta163$SELFINSURE[dta163$COVTYPE=="Plan you purchased yourself"]<-1

dta163$EMPLINSURE <- 0
dta163$EMPLINSURE[dta163$COVTYPE=="Plan through your employer"]<-1
dta163$EMPLINSURE[dta163$COVTYPE=="Plan through your spouse's employer"]<-1

#dta163$PREEXIST <- 1*(dta163$PREX=="Yes, someone in household has pre-existing #condition")
dta163$PREEXIST <- NA

dta163$HURT <- NA

dta163$HELPHOW <- NA

dta163$HURTHOW <- NA

dta163$PSRAID <- dta163$ID
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s163 <- subsetn(dta163,select=masterlist, subset=T)



#### June 2017
dta162 <- read.por.upper("hni162.por",to.data.frame=T)

dta162$PREEXIST <- 0
dta162$PREEXIST[dta162$PREX=="Yes, someone in this household has a pre-existing condition"] <- 1


dta162$INCOME <- NA
dta162$INCOME[dta162$QD14=="Less than $20,000"] <- 10
dta162$INCOME[dta162$QD14=="$20,000 to less than $30,000"] <- 25
dta162$INCOME[dta162$QD14=="$30,000 to less than $40,000"] <- 35
dta162$INCOME[dta162$QD14=="$40,000 to less than $50,000"] <- 45
dta162$INCOME[dta162$QD14=="$50,000 to less than $75,000"] <- 62.5
dta162$INCOME[dta162$QD14=="$75,000 to less than $90,000"] <- 82.5
dta162$INCOME[dta162$QD14=="$90,000 to less than $100,000"] <- 95
dta162$INCOME[dta162$QD14=="$100,000 or more"] <- 200

dta162$HISP <- 0
dta162$HISP[dta162$QD12A=="(DO NOT READ) Don't know/Refused"] <- 1
dta162$HISP[dta162$QD12A=="Another country"] <- 1
dta162$HISP[dta162$QD12A=="Puerto Rico"] <- 1
dta162$HISP[dta162$QD12A=="U.S."] <- 1

dta162$EDUC <- NA
dta162$EDUC[dta162$EDUC2=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta162$EDUC[dta162$EDUC2=="High school incomplete (Grades 9-11 or Grade 12 with no diploma)"] <- 10
dta162$EDUC[dta162$EDUC2=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta162$EDUC[dta162$EDUC2=="Some college, no degree (includes some community college)"] <- 13
dta162$EDUC[dta162$EDUC2=="Two year associate degree from a college or university"] <- 14
dta162$EDUC[dta162$EDUC2=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta162$EDUC[dta162$EDUC2=="Some postgraduate or professional school, no postgraduate degree"] <- 17
dta162$EDUC[dta162$EDUC2=="Post-graduate or professional degree, including master's, doctorate, medical, or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta162$PID <- NA
dta162$PID[dta162$PARTY=="Democrat"] <- 1
dta162$PID[dta162$PARTY %in% c("Independent","Or what? (INTERVIEWER: INCLUDE 'OTHER' AND 'NONE' HERE)")] <- 2
dta162$PID[dta162$PARTY=="Republican"] <- 3

dta162$PID5 <- NA
dta162$PID5[dta162$PID==1] <- 1
dta162$PID5[dta162$PARTYLEA=="Democratic"] <- 2
dta162$PID5[dta162$PARTYLEA %in% c("Independent/don't lean to either party (VOL.)", "Other party (VOL.)", "Don't Know")] <- 3
dta162$PID5[dta162$PARTYLEA=="Republican"] <- 4
dta162$PID5[dta162$PID==3] <- 5

dta162$REGISTERED <- NA
dta162$REGISTERED[dta162$RVOTE=="Yes"] <- 1
dta162$REGISTERED[dta162$RVOTE=="No"] <- 2

dta162$BETPER <- NA

dta162$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta162$SUPPORT <- NA
#dta162$SUPPORT[dta162$Q1=="Strongly support"] <- 4
#dta162$SUPPORT[dta162$Q1=="Somewhat support"] <- 3
#dta162$SUPPORT[dta162$Q1=="Somewhat oppose"] <- 2
#dta162$SUPPORT[dta162$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta162$BLACK <- (dta162$RACE=="Black or African-American")*1
dta162$ASIAN <- (dta162$RACE=="Asian")*1
dta162$OTHER <- (dta162$RACE=="Other or mixed race (SPECIFY)")*1

dta162$AGE <- as.numeric(as.character(dta162$AGE))
dta162$MEDICARE <- (dta162$AGE > 64)*1

dta162$COVERED <- (dta162$COVERAGE=="Covered by health insurance")*1

dta162$IDEO <- NA
dta162$IDEO[dta162$QD8B=="Liberal"] <- 3
dta162$IDEO[dta162$QD8B=="Moderate"] <- 2
dta162$IDEO[dta162$QD8B=="Conservative"] <- 1

dta162$FAVOR <- NA
dta162$FAVOR[dta162$Q1=="Very favorable"] <- 4
dta162$FAVOR[dta162$Q1=="Somewhat favorable"] <- 3
dta162$FAVOR[dta162$Q1=="Somewhat unfavorable"] <- 2
dta162$FAVOR[dta162$Q1=="Very unfavorable"] <- 1

# Question Still Not Asked
dta162$SELFEMPLOY <- NA
#dta162$SELFEMPLOY[dta162$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta162$RETIRED <- 0
dta162$RETIRED[dta162$QD3=="Retired"] <- 1

dta162$MEDICARESR <- 0
dta162$MEDICARESR <- 1*(dta162$COVTYPE=="Medicare")
dta162$MEDICARESR[dta162$COVTYPE %in% c(NA)] <- 0

dta162$MEDICAID <- 0
dta162$MEDICAID <- 1*(dta162$COVTYPE=="Medicaid/[STATE-SPECIFIC MEDICAID NAME]")
dta162$MEDICAID[dta162$COVTYPE %in% c(NA)] <- 0

dta162$HEALTH <- NA
dta162$HEALTH[dta162$QD2=="Excellent"] <- 5
dta162$HEALTH[dta162$QD2=="Very good"] <- 4
dta162$HEALTH[dta162$QD2=="Good"] <- 3
dta162$HEALTH[dta162$QD2=="Only fair"] <- 2
dta162$HEALTH[dta162$QD2=="Poor"] <- 1

dta162$SAWAD <- NA
dta162$SAWADPOS <- NA
dta162$SAWADNEG <- NA
dta162$SAWADBOTH <- NA

#dta162$STATE <- dta162$state
#dta162$SSTATE <- dta162$STATE

dta162$MALE <- 1*(dta162$D1=="Male")

dta162$NUMBER <- 162

dta162$MONTH <- 101

dta162$MARKET <- 0
dta162$MARKET[dta162$COVSELF=="From healthcare.gov or [STATE MARKETPLACE NAME]"]<-1

dta162$SELFINSURE <- 0
dta162$SELFINSURE[dta162$COVTYPE=="Plan you purchased yourself"]<-1

dta162$EMPLINSURE <- 0
dta162$EMPLINSURE[dta162$COVTYPE=="Plan through your employer"]<-1
dta162$EMPLINSURE[dta162$COVTYPE=="Plan through your spouse's employer"]<-1

dta162$PREEXIST <- 1*(dta162$PREX=="Yes, someone in household has pre-existing condition")

dta162$HURT <- NA

dta162$HELPHOW <- NA

dta162$HURTHOW <- NA

dta162$PSRAID <- dta162$ID
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s162 <- subsetn(dta162,select=masterlist, subset=T)




#### May 2017
dta161 <- read.por.upper("hni161.por",to.data.frame=T)

dta161$INCOME <- NA
dta161$INCOME[dta161$QD14=="Less than $20,000"] <- 10
dta161$INCOME[dta161$QD14=="$20,000 to less than $30,000"] <- 25
dta161$INCOME[dta161$QD14=="$30,000 to less than $40,000"] <- 35
dta161$INCOME[dta161$QD14=="$40,000 to less than $50,000"] <- 45
dta161$INCOME[dta161$QD14=="$50,000 to less than $75,000"] <- 62.5
dta161$INCOME[dta161$QD14=="$75,000 to less than $90,000"] <- 82.5
dta161$INCOME[dta161$QD14=="$90,000 to less than $100,000"] <- 95
dta161$INCOME[dta161$QD14=="$100,000 or more"] <- 200

dta161$HISP <- 0
dta161$HISP[dta161$QD12A=="(DO NOT READ) Don't know/Refused"] <- 1
dta161$HISP[dta161$QD12A=="Another country"] <- 1
dta161$HISP[dta161$QD12A=="Puerto Rico"] <- 1
dta161$HISP[dta161$QD12A=="U.S."] <- 1

dta161$EDUC <- NA
dta161$EDUC[dta161$EDUC2=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta161$EDUC[dta161$EDUC2=="High school incomplete (Grades 9-11 or Grade 12 with no diploma)"] <- 10
dta161$EDUC[dta161$EDUC2=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta161$EDUC[dta161$EDUC2=="Some college, no degree (includes some community college)"] <- 13
dta161$EDUC[dta161$EDUC2=="Two year associate degree from a college or university"] <- 14
dta161$EDUC[dta161$EDUC2=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta161$EDUC[dta161$EDUC2=="Some postgraduate or professional school, no postgraduate degree"] <- 17
dta161$EDUC[dta161$EDUC2=="Post-graduate or professional degree, including master's, doctorate, medical, or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta161$PID <- NA
dta161$PID[dta161$QD8=="Democrat"] <- 1
dta161$PID[dta161$QD8 %in% c("Independent","Or what (includes Other and None)")] <- 2
dta161$PID[dta161$QD8=="Republican"] <- 3

dta161$PID5 <- NA
dta161$PID5[dta161$PID==1] <- 1
dta161$PID5[dta161$QD8A=="Democratic"] <- 2
dta161$PID5[dta161$QD8A %in% c("(DO NOT READ) Independent/don't lean to either party", "(DO NOT READ) Other party", "(DO NOT READ) Don't know/Refused")] <- 3
dta161$PID5[dta161$QD8A=="Republican"] <- 4
dta161$PID5[dta161$PID==3] <- 5

dta161$REGISTERED <- NA
dta161$REGISTERED[dta161$QD9=="Yes"] <- 1
dta161$REGISTERED[dta161$QD9=="No"] <- 2

dta161$BETPER <- NA

dta161$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta161$SUPPORT <- NA
#dta161$SUPPORT[dta161$Q1=="Strongly support"] <- 4
#dta161$SUPPORT[dta161$Q1=="Somewhat support"] <- 3
#dta161$SUPPORT[dta161$Q1=="Somewhat oppose"] <- 2
#dta161$SUPPORT[dta161$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta161$BLACK <- (dta161$RACE=="Black or African-American")*1
dta161$ASIAN <- (dta161$RACE=="Asian")*1
dta161$OTHER <- (dta161$RACE=="Other or mixed race (SPECIFY)")*1

dta161$AGE <- as.numeric(as.character(dta161$AGE))
dta161$MEDICARE <- (dta161$AGE > 64)*1

dta161$COVERED <- (dta161$QD4=="Covered by health insurance")*1

dta161$IDEO <- NA
dta161$IDEO[dta161$QD8B=="Liberal"] <- 3
dta161$IDEO[dta161$QD8B=="Moderate"] <- 2
dta161$IDEO[dta161$QD8B=="Conservative"] <- 1

dta161$FAVOR <- NA
dta161$FAVOR[dta161$Q1=="Very favorable"] <- 4
dta161$FAVOR[dta161$Q1=="Somewhat favorable"] <- 3
dta161$FAVOR[dta161$Q1=="Somewhat unfavorable"] <- 2
dta161$FAVOR[dta161$Q1=="Very unfavorable"] <- 1

# Question Still Not Asked
dta161$SELFEMPLOY <- NA
#dta161$SELFEMPLOY[dta161$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta161$RETIRED <- 0
dta161$RETIRED[dta161$QD3=="Retired"] <- 1

dta161$MEDICARESR <- 0
dta161$MEDICARESR <- 1*(dta161$QD4A=="Medicare")
dta161$MEDICARESR[dta161$QD4A %in% c(NA)] <- 0

dta161$MEDICAID <- 0
dta161$MEDICAID <- 1*(dta161$QD4A=="Medicaid/[STATE-SPECIFIC MEDICAID NAME]")
dta161$MEDICAID[dta161$QD4A %in% c(NA)] <- 0

dta161$HEALTH <- NA
dta161$HEALTH[dta161$QD2=="Excellent"] <- 5
dta161$HEALTH[dta161$QD2=="Very good"] <- 4
dta161$HEALTH[dta161$QD2=="Good"] <- 3
dta161$HEALTH[dta161$QD2=="Only fair"] <- 2
dta161$HEALTH[dta161$QD2=="Poor"] <- 1

dta161$SAWAD <- NA
dta161$SAWADPOS <- NA
dta161$SAWADNEG <- NA
dta161$SAWADBOTH <- NA

#dta161$STATE <- dta161$state
dta161$SSTATE <- dta161$STATE

dta161$MALE <- 1*(dta161$SEX=="Male")

dta161$NUMBER <- 161

dta161$MONTH <- 100

dta161$MARKET <- 0
dta161$MARKET[dta161$Q18=="From healthcare.gov or [STATE MARKETPLACE NAME]"]<-1

dta161$SELFINSURE <- 0
dta161$SELFINSURE[dta161$QD4A=="Plan you purchased yourself"]<-1

dta161$EMPLINSURE <- 0
dta161$EMPLINSURE[dta161$QD4A=="Plan through your employer"]<-1
dta161$EMPLINSURE[dta161$QD4A=="Plan through your spouse's employer"]<-1

dta161$PREEXIST <- 1*(dta161$Q23=="Yes, someone in household has pre-existing condition")

dta161$HURT <- NA

dta161$HELPHOW <- NA

dta161$HURTHOW <- NA

#dta161$PSRAID <- dta161$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s161 <- subsetn(dta161,select=masterlist, subset=T)








##### April 2017
dta160 <- read.csv.upper("hni160.csv")

dta160$INCOME <- NA
dta160$INCOME[dta160$QD14=="Less than $20,000"] <- 10
dta160$INCOME[dta160$QD14=="$20,000 to less than $30,000"] <- 25
dta160$INCOME[dta160$QD14=="$30,000 to less than $40,000"] <- 35
dta160$INCOME[dta160$QD14=="$40,000 to less than $50,000"] <- 45
dta160$INCOME[dta160$QD14=="$50,000 to less than $75,000"] <- 62.5
dta160$INCOME[dta160$QD14=="$75,000 to less than $90,000"] <- 82.5
dta160$INCOME[dta160$QD14=="$90,000 to less than $100,000"] <- 95
dta160$INCOME[dta160$QD14=="$100,000 or more"] <- 200

dta160$HISP <- 0
dta160$HISP[dta160$QD12A=="(DO NOT READ) Don't know/Refused"] <- 1
dta160$HISP[dta160$QD12A=="Another country"] <- 1
dta160$HISP[dta160$QD12A=="Puerto Rico"] <- 1
dta160$HISP[dta160$QD12A=="U.S."] <- 1

dta160$EDUC <- NA
dta160$EDUC[dta160$EDUC2=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta160$EDUC[dta160$EDUC2=="High school incomplete (Grades 9-11 or Grade 12 with no diploma)"] <- 10
dta160$EDUC[dta160$EDUC2=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta160$EDUC[dta160$EDUC2=="Some college, no degree (includes some community college)"] <- 13
dta160$EDUC[dta160$EDUC2=="Two year associate degree from a college or university"] <- 14
dta160$EDUC[dta160$EDUC2=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta160$EDUC[dta160$EDUC2=="Some postgraduate or professional school, no postgraduate degree"] <- 17
dta160$EDUC[dta160$EDUC2=="Post-graduate or professional degree, including master's, doctorate, medical, or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta160$PID <- NA
dta160$PID[dta160$QD8=="Democrat"] <- 1
dta160$PID[dta160$QD8 %in% c("Independent","Or what (includes Other and None)")] <- 2
dta160$PID[dta160$QD8=="Republican"] <- 3

dta160$PID5 <- NA
dta160$PID5[dta160$PID==1] <- 1
dta160$PID5[dta160$QD8A=="Democratic"] <- 2
dta160$PID5[dta160$QD8A %in% c("(DO NOT READ) Independent/don't lean to either party", "(DO NOT READ) Other party", "(DO NOT READ) Don't know/Refused")] <- 3
dta160$PID5[dta160$QD8A=="Republican"] <- 4
dta160$PID5[dta160$PID==3] <- 5

dta160$REGISTERED <- NA
dta160$REGISTERED[dta160$QD9=="Yes"] <- 1
dta160$REGISTERED[dta160$QD9=="No"] <- 2

dta160$BETPER <- NA

dta160$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta160$SUPPORT <- NA
#dta160$SUPPORT[dta160$Q1=="Strongly support"] <- 4
#dta160$SUPPORT[dta160$Q1=="Somewhat support"] <- 3
#dta160$SUPPORT[dta160$Q1=="Somewhat oppose"] <- 2
#dta160$SUPPORT[dta160$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta160$BLACK <- (dta160$RACE=="Black or African-American")*1
dta160$ASIAN <- (dta160$RACE=="Asian")*1
dta160$OTHER <- (dta160$RACE=="Other or mixed race (SPECIFY)")*1

dta160$AGE <- dta160$AGE
dta160$MEDICARE <- (dta160$AGE > 64)*1

dta160$COVERED <- (dta160$QD4=="Covered by health insurance")*1

dta160$IDEO <- NA
dta160$IDEO[dta160$QD8B=="Liberal"] <- 3
dta160$IDEO[dta160$QD8B=="Moderate"] <- 2
dta160$IDEO[dta160$QD8B=="Conservative"] <- 1

dta160$FAVOR <- NA
dta160$FAVOR[dta160$Q1=="Very favorable"] <- 4
dta160$FAVOR[dta160$Q1=="Somewhat favorable"] <- 3
dta160$FAVOR[dta160$Q1=="Somewhat unfavorable"] <- 2
dta160$FAVOR[dta160$Q1=="Very unfavorable"] <- 1

# Question Still Not Asked
dta160$SELFEMPLOY <- NA
#dta160$SELFEMPLOY[dta160$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta160$RETIRED <- 0
dta160$RETIRED[dta160$QD3=="Retired"] <- 1

dta160$MEDICARESR <- 0
dta160$MEDICARESR <- 1*(dta160$QD4A=="Medicare")
dta160$MEDICARESR[dta160$QD4A %in% c(NA)] <- 0

dta160$MEDICAID <- 0
dta160$MEDICAID <- 1*(dta160$QD4A=="Medicaid/[STATE-SPECIFIC MEDICAID NAME]")
dta160$MEDICAID[dta160$QD4A %in% c(NA)] <- 0

dta160$HEALTH <- NA
dta160$HEALTH[dta160$QD2=="Excellent"] <- 5
dta160$HEALTH[dta160$QD2=="Very good"] <- 4
dta160$HEALTH[dta160$QD2=="Good"] <- 3
dta160$HEALTH[dta160$QD2=="Only fair"] <- 2
dta160$HEALTH[dta160$QD2=="Poor"] <- 1

dta160$SAWAD <- NA
dta160$SAWADPOS <- NA
dta160$SAWADNEG <- NA
dta160$SAWADBOTH <- NA

dta160$STATE <- dta160$STATE
dta160$SSTATE <- dta160$STATE

dta160$MALE <- 1*(dta160$SEX=="Male")

dta160$NUMBER <- 160

dta160$MONTH <- 99

dta160$MARKET <- 0
dta160$MARKET[dta160$Q24=="From healthcare.gov or [STATE MARKETPLACE NAME]"]<-1

dta160$SELFINSURE <- 0
dta160$SELFINSURE[dta160$QD4A=="Plan you purchased yourself"]<-1

dta160$EMPLINSURE <- 0
dta160$EMPLINSURE[dta160$QD4A=="Plan through your employer"]<-1
dta160$EMPLINSURE[dta160$QD4A=="Plan through your spouse's employer"]<-1

dta160$PREEXIST <- NA

dta160$HURT <- NA

dta160$HELPHOW <- NA

dta160$HURTHOW <- NA

dta160$REGISTERED <- NA

#sort(table(dta160$Q2CD[dta160$FAVOR==1]))/sum(sort(table(dta160$Q2CD[dta160$FAVOR==1])))

###lout160a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta160)
##summary(#lout160a)
###mf160a <- model.frame(#lout160a)

#### full data
#nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
##mf160a2 <- subsetn(dta160,select=nms)

###lout160b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta160)
##summary(#lout160b)
###mf160b <- model.frame(#lout160b)

#lout160d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta160)
#summary(#lout160d)
##fv160d <- model.frame(#lout160d)
fvnms <- c("HELPHOW","HURTHOW","HURT","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv160a2 <- subsetn(dta160,select=fvnms)

dta160$PSRAID <- dta160$PSRAID
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s160 <- subsetn(dta160,select=masterlist, subset=T)



##### March 2017
dta159 <- read.por.upper("hni159.por",to.data.frame=T)

dta159$INCOME <- NA
dta159$INCOME[dta159$QD14=="Less than $20,000"] <- 10
dta159$INCOME[dta159$QD14=="$20,000 to less than $30,000"] <- 25
dta159$INCOME[dta159$QD14=="$30,000 to less than $40,000"] <- 35
dta159$INCOME[dta159$QD14=="$40,000 to less than $50,000"] <- 45
dta159$INCOME[dta159$QD14=="$50,000 to less than $75,000"] <- 62.5
dta159$INCOME[dta159$QD14=="$75,000 to less than $90,000"] <- 82.5
dta159$INCOME[dta159$QD14=="$90,000 to less than $100,000"] <- 95
dta159$INCOME[dta159$QD14=="$100,000 or more"] <- 200

dta159$HISP2 <- dta159$HISP
dta159$HISP <- (dta159$HISP2=="Yes")*1

dta159$EDUC <- NA
dta159$EDUC[dta159$EDUC2=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta159$EDUC[dta159$EDUC2=="High school incomplete (Grades 9-11 or Grade 12 with no diploma)"] <- 10
dta159$EDUC[dta159$EDUC2=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta159$EDUC[dta159$EDUC2=="Some college, no degree (includes some community college)"] <- 13
dta159$EDUC[dta159$EDUC2=="Two year associate degree from a college or university"] <- 14
dta159$EDUC[dta159$EDUC2=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta159$EDUC[dta159$EDUC2=="Some postgraduate or professional school, no postgraduate degree"] <- 17
dta159$EDUC[dta159$EDUC2=="Post-graduate or professional degree, including master's, doctorate, medical, or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta159$PID <- NA
dta159$PID[dta159$QD8=="Democrat"] <- 1
dta159$PID[dta159$QD8 %in% c("Independent","Or what (includes Other and None)")] <- 2
dta159$PID[dta159$QD8=="Republican"] <- 3

dta159$PID5 <- NA
dta159$PID5[dta159$PID==1] <- 1
dta159$PID5[dta159$QD8A=="Democratic"] <- 2
dta159$PID5[dta159$QD8A %in% c("(DO NOT READ) Independent/don't lean to either party", "(DO NOT READ) Other party", "(DO NOT READ) Don't know/Refused")] <- 3
dta159$PID5[dta159$QD8A=="Republican"] <- 4
dta159$PID5[dta159$PID==3] <- 5

dta159$BETPER <- NA

dta159$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta159$SUPPORT <- NA
#dta159$SUPPORT[dta159$Q1=="Strongly support"] <- 4
#dta159$SUPPORT[dta159$Q1=="Somewhat support"] <- 3
#dta159$SUPPORT[dta159$Q1=="Somewhat oppose"] <- 2
#dta159$SUPPORT[dta159$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta159$BLACK <- (dta159$RACE=="Black or African-American")*1
dta159$ASIAN <- (dta159$RACE=="Asian")*1
dta159$OTHER <- (dta159$RACE=="Other or mixed race (SPECIFY)")*1

dta159$AGE <- as.numeric(as.character(dta159$AGE))
dta159$AGE[dta159$AGE==99] <- NA
dta159$MEDICARE <- (dta159$AGE > 64)*1

dta159$COVERED <- (dta159$QD4=="Covered by health insurance")*1

dta159$IDEO <- NA
dta159$IDEO[dta159$QD8B=="Liberal"] <- 3
dta159$IDEO[dta159$QD8B=="Moderate"] <- 2
dta159$IDEO[dta159$QD8B=="Conservative"] <- 1

dta159$FAVOR <- NA
dta159$FAVOR[dta159$Q2=="Very favorable"] <- 4
dta159$FAVOR[dta159$Q2=="Somewhat favorable"] <- 3
dta159$FAVOR[dta159$Q2=="Somewhat unfavorable"] <- 2
dta159$FAVOR[dta159$Q2=="Very unfavorable"] <- 1

# Question Still Not Asked
dta159$SELFEMPLOY <- NA
#dta159$SELFEMPLOY[dta159$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta159$RETIRED <- 0
dta159$RETIRED[dta159$QD3=="Retired"] <- 1

dta159$MEDICARESR <- 0
dta159$MEDICARESR <- 1*(dta159$QD4A=="Medicare")
dta159$MEDICARESR[dta159$QD4A %in% c(NA)] <- 0

dta159$MEDICAID <- 0
dta159$MEDICAID <- 1*(dta159$QD4A=="Medicaid/[STATE-SPECIFIC MEDICAID NAME]")
dta159$MEDICAID[dta159$QD4A %in% c(NA)] <- 0

dta159$HEALTH <- NA
dta159$HEALTH[dta159$QD2=="Excellent"] <- 5
dta159$HEALTH[dta159$QD2=="Very good"] <- 4
dta159$HEALTH[dta159$QD2=="Good"] <- 3
dta159$HEALTH[dta159$QD2=="Only fair"] <- 2
dta159$HEALTH[dta159$QD2=="Poor"] <- 1

dta159$SAWAD <- NA
dta159$SAWADPOS <- NA
dta159$SAWADNEG <- NA
dta159$SAWADBOTH <- NA

dta159$SSTATE <- dta159$STATE

dta159$MALE <- 1*(dta159$SEX=="Male")

dta159$NUMBER <- 159

dta159$MONTH <- 98

dta159$MARKET <- 0
dta159$MARKET[dta159$Q31=="From healthcare.gov or [STATE MARKETPLACE NAME]"]<-1

dta159$SELFINSURE <- 0
dta159$SELFINSURE[dta159$QD4A=="Plan you purchased yourself"]<-1

dta159$EMPLINSURE <- 0
dta159$EMPLINSURE[dta159$QD4A=="Plan through your employer"]<-1
dta159$EMPLINSURE[dta159$QD4A=="Plan through your spouse's employer"]<-1

dta159$PREEXIST <- NA

dta159$HURT <- NA

dta159$HELPHOW <- NA

dta159$HURTHOW <- NA

#sort(table(dta159$Q2CD[dta159$FAVOR==1]))/sum(sort(table(dta159$Q2CD[dta159$FAVOR==1])))

###lout159a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta159)
##summary(#lout159a)
###mf159a <- model.frame(#lout159a)

#### full data
#nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
##mf159a2 <- subsetn(dta159,select=nms)

###lout159b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta159)
##summary(#lout159b)
###mf159b <- model.frame(#lout159b)

#lout159d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta159)
#summary(#lout159d)
##fv159d <- model.frame(#lout159d)
##fvnms <- c("HELPHOW","HURTHOW","HURT","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
##fv159a2 <- subsetn(dta159,select=fvnms)

#dta159$PSRAID #<- dta159$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s159 <- subsetn(dta159,select=masterlist, subset=T)



##### February 2017
dta158 <- read.por.upper("hni158.por",to.data.frame=T)

dta158$INCOME <- NA
dta158$INCOME[dta158$QD14=="Less than $20,000"] <- 10
dta158$INCOME[dta158$QD14=="$20,000 to less than $30,000"] <- 25
dta158$INCOME[dta158$QD14=="$30,000 to less than $40,000"] <- 35
dta158$INCOME[dta158$QD14=="$40,000 to less than $50,000"] <- 45
dta158$INCOME[dta158$QD14=="$50,000 to less than $75,000"] <- 62.5
dta158$INCOME[dta158$QD14=="$75,000 to less than $90,000"] <- 82.5
dta158$INCOME[dta158$QD14=="$90,000 to less than $100,000"] <- 95
dta158$INCOME[dta158$QD14=="$100,000 or more"] <- 200

dta158$HISP2 <- dta158$HISP
dta158$HISP <- (dta158$HISP2=="Yes")*1

dta158$EDUC <- NA
dta158$EDUC[dta158$EDUC2=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta158$EDUC[dta158$EDUC2=="High school incomplete (Grades 9-11 or Grade 12 with no diploma)"] <- 10
dta158$EDUC[dta158$EDUC2=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta158$EDUC[dta158$EDUC2=="Some college, no degree (includes some community college)"] <- 13
dta158$EDUC[dta158$EDUC2=="Two year associate degree from a college or university"] <- 14
dta158$EDUC[dta158$EDUC2=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta158$EDUC[dta158$EDUC2=="Some postgraduate or professional school, no postgraduate degree"] <- 17
dta158$EDUC[dta158$EDUC2=="Post-graduate or professional degree, including master's, doctorate, medical, or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta158$PID <- NA
dta158$PID[dta158$QD8=="Democrat"] <- 1
dta158$PID[dta158$QD8 %in% c("Independent","Or what (includes Other and None)")] <- 2
dta158$PID[dta158$QD8=="Republican"] <- 3

dta158$PID5 <- NA
dta158$PID5[dta158$PID==1] <- 1
dta158$PID5[dta158$QD8A=="Democratic"] <- 2
dta158$PID5[dta158$QD8A %in% c("(DO NOT READ) Independent/don't lean to either party", "(DO NOT READ) Other party", "(DO NOT READ) Don't know/Refused")] <- 3
dta158$PID5[dta158$QD8A=="Republican"] <- 4
dta158$PID5[dta158$PID==3] <- 5

dta158$REGISTERED <- NA
dta158$REGISTERED[dta158$QD9=="Yes"] <- 1
dta158$REGISTERED[dta158$QD9=="No"] <- 2

dta158$VOTED <- NA
dta158$VOTED[dta158$Q31=="Yes, voted"] <- 1
dta158$VOTED[dta158$Q31=="No, did not vote"] <- 2

dta158$BETPER <- NA

dta158$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta158$SUPPORT <- NA
#dta158$SUPPORT[dta158$Q1=="Strongly support"] <- 4
#dta158$SUPPORT[dta158$Q1=="Somewhat support"] <- 3
#dta158$SUPPORT[dta158$Q1=="Somewhat oppose"] <- 2
#dta158$SUPPORT[dta158$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta158$BLACK <- (dta158$RACE=="Black or African-American")*1
dta158$ASIAN <- (dta158$RACE=="Asian")*1
dta158$OTHER <- (dta158$RACE=="Other or mixed race (SPECIFY)")*1

dta158$AGE <- as.numeric(as.character(dta158$AGE))
dta158$AGE[dta158$AGE==99] <- NA
dta158$MEDICARE <- (dta158$AGE > 64)*1


dta158$COVERED <- (dta158$QD4=="Covered by health insurance")*1


dta158$IDEO <- NA
dta158$IDEO[dta158$QD8B=="Liberal"] <- 3
dta158$IDEO[dta158$QD8B=="Moderate"] <- 2
dta158$IDEO[dta158$QD8B=="Conservative"] <- 1

dta158$FAVOR <- NA
dta158$FAVOR[dta158$Q2=="Very favorable"] <- 4
dta158$FAVOR[dta158$Q2=="Somewhat favorable"] <- 3
dta158$FAVOR[dta158$Q2=="Somewhat unfavorable"] <- 2
dta158$FAVOR[dta158$Q2=="Very unfavorable"] <- 1

# Question Still Not Asked
dta158$SELFEMPLOY <- NA
#dta158$SELFEMPLOY[dta158$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta158$RETIRED <- 0
dta158$RETIRED[dta158$QD3=="Retired"] <- 1

dta158$MEDICARESR <- 0
dta158$MEDICARESR <- 1*(dta158$QD4A=="Medicare")
dta158$MEDICARESR[dta158$QD4A %in% c(NA)] <- 0

dta158$MEDICAID <- 0
dta158$MEDICAID <- 1*(dta158$QD4A=="Medicaid/[STATE-SPECIFIC MEDICAID NAME]")
dta158$MEDICAID[dta158$QD4A %in% c(NA)] <- 0


dta158$HEALTH <- NA
dta158$HEALTH[dta158$QD2=="Excellent"] <- 5
dta158$HEALTH[dta158$QD2=="Very good"] <- 4
dta158$HEALTH[dta158$QD2=="Good"] <- 3
dta158$HEALTH[dta158$QD2=="Only fair"] <- 2
dta158$HEALTH[dta158$QD2=="Poor"] <- 1

dta158$SAWAD <- NA
dta158$SAWADPOS <- NA
dta158$SAWADNEG <- NA
dta158$SAWADBOTH <- NA

dta158$SSTATE <- dta158$STATE

dta158$MALE <- 1*(dta158$SEX=="Male")

dta158$NUMBER <- 158

dta158$MONTH <- 97

dta158$MARKET <- 0
dta158$MARKET[dta158$Q25=="From healthcare.gov or [STATE MARKETPLACE NAME]"]<-1

dta158$SELFINSURE <- 0
dta158$SELFINSURE[dta158$QD4A=="Plan you purchased yourself"]<-1

dta158$EMPLINSURE <- 0
dta158$EMPLINSURE[dta158$QD4A=="Plan through your employer"]<-1
dta158$EMPLINSURE[dta158$QD4A=="Plan through your spouse's employer"]<-1

dta158$PREEXIST <- NA
dta158$PREEXIST[dta158$Q27=="Yes"] <- 1
dta158$PREEXIST[dta158$Q27=="No"] <- 2

dta158$HURT <- NA

dta158$HELPHOW <- NA

dta158$HURTHOW <- NA

#sort(table(dta158$Q2CD[dta158$FAVOR==1]))/sum(sort(table(dta158$Q2CD[dta158$FAVOR==1])))

###lout158a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta158)
##summary(#lout158a)
###mf158a <- model.frame(#lout158a)

#### full data
#nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
##mf158a2 <- subsetn(dta158,select=nms)

###lout158b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta158)
##summary(#lout158b)
###mf158b <- model.frame(#lout158b)

#lout158d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta158)
#summary(#lout158d)
##fv158d <- model.frame(#lout158d)
fvnms <- c("HELPHOW","HURTHOW","HURT","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv158a2 <- subsetn(dta158,select=fvnms)


dta158$PSRAID <- dta158$PSRAID
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s158 <- subsetn(dta158,select=masterlist, subset=T)



##### December 2016
dta157 <- read.csv.upper("hni157.csv")

dta157$INCOME <- NA
dta157$INCOME[dta157$QD14==1] <- 10
dta157$INCOME[dta157$QD14==2] <- 25
dta157$INCOME[dta157$QD14==3] <- 35
dta157$INCOME[dta157$QD14==4] <- 45
dta157$INCOME[dta157$QD14==5] <- 62.5
dta157$INCOME[dta157$QD14==6] <- 82.5
dta157$INCOME[dta157$QD14==7] <- 95
dta157$INCOME[dta157$QD14==8] <- 200

# for some reason, R misinterprets the following lines, so you have to refactorize them
dta157$HISP2 <- dta157$HISP
dta157$HISP[as.factor(as.character(dta157$HISP2))==2] <- 0
dta157$HISP[as.factor(as.character(dta157$HISP2))==9] <- 0
dta157$HISP[as.factor(as.character(dta157$HISP2))==1] <- 1

dta157$EDUC <- NA
dta157$EDUC[dta157$EDUC2==1] <- 6
dta157$EDUC[dta157$EDUC2==2] <- 10
dta157$EDUC[dta157$EDUC2==3] <- 12
dta157$EDUC[dta157$EDUC2==4] <- 13
dta157$EDUC[dta157$EDUC2==5] <- 14
dta157$EDUC[dta157$EDUC2==6] <- 16
dta157$EDUC[dta157$EDUC2==7] <- 17
dta157$EDUC[dta157$EDUC2==8] <- 19

# R also doesn't like these factors when they're used with a >= or <=, so you have to transform
dta157$PID <- NA
dta157$PID[dta157$QD8=="Democrat"] <- 1
dta157$PID[dta157$QD8 %in% c("Independent", "Or what (inludes Other and None)")] <- 2
dta157$PID[dta157$QD8=="Republican"] <- 3

dta157$PID5 <- NA
dta157$PID5[dta157$PID==1] <- 1
dta157$PID5[dta157$QD8A=="Democratic"] <- 2
dta157$PID5[dta157$QD8A %in% c("(DO NOT READ) Independent/don't lean to either party", "(DO NOT READ) Other party", "(DO NOT READ) Don't know/Refused")] <- 3
dta157$PID5[dta157$QD8A=="Republican"] <- 4
dta157$PID5[dta157$PID==3] <- 5

dta157$REGISTERED <- NA
dta157$REGISTERED[dta157$QD9=="Yes"] <- 1
dta157$REGISTERED[dta157$QD9=="No"] <- 2

dta157$BETPER <- NA
dta157$BETPER[dta157$Q5C=="Good"] <- 1
dta157$BETPER[dta157$Q5C=="Bad"] <- 2
dta157$BETPER[dta157$Q5C=="Not make much of a difference"] <- 3

dta157$BETCOU <- NA
dta157$BETCOU[dta157$Q5A=="Good"] <- 1
dta157$BETCOU[dta157$Q5A=="Bad"] <- 2
dta157$BETCOU[dta157$Q5A=="Not make much of a difference"] <- 3

# NOTE: var replaced with FAVOR var.
dta157$SUPPORT <- NA
#dta157$SUPPORT[dta157$Q1=="Strongly support"] <- 4
#dta157$SUPPORT[dta157$Q1=="Somewhat support"] <- 3
#dta157$SUPPORT[dta157$Q1=="Somewhat oppose"] <- 2
#dta157$SUPPORT[dta157$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta157$BLACK <- (dta157$RACE==2)*1
dta157$ASIAN <- (dta157$RACE==3)*1
dta157$OTHER <- (dta157$RACE==4)*1

#dta157$AGE <- dta157$age
dta157$AGE[dta157$AGE==99] <- NA
dta157$MEDICARE <- (as.numeric(as.character(dta157$AGE)) > 64)*1

dta157$COVERED <- (dta157$QD4==1)*1

dta157$IDEO <- NA
dta157$IDEO[dta157$QD8B==1] <- 3
dta157$IDEO[dta157$QD8B==2] <- 2
dta157$IDEO[dta157$QD8B==3] <- 1

dta157$FAVOR <- NA
dta157$FAVOR[dta157$Q3==1] <- 4
dta157$FAVOR[dta157$Q3==2] <- 3
dta157$FAVOR[dta157$Q3==3] <- 2
dta157$FAVOR[dta157$Q3==4] <- 1

# Question Still Not Asked
dta157$SELFEMPLOY <- NA
#dta157$SELFEMPLOY[dta157$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta157$RETIRED <- 0
dta157$RETIRED[dta157$QD3==6] <- 1

dta157$MEDICARESR <- 0
dta157$MEDICARESR <- 1*(dta157$QD4A==4)
dta157$MEDICARESR[dta157$COVERED==0] <- 0

dta157$MEDICAID <- 0
dta157$MEDICAID <- 1*(dta157$QD4A==5)
dta157$MEDICAID[dta157$COVERED==0] <- 0


dta157$HEALTH <- NA
dta157$HEALTH[dta157$QD2==1] <- 5
dta157$HEALTH[dta157$QD2==2] <- 4
dta157$HEALTH[dta157$QD2==3] <- 3
dta157$HEALTH[dta157$QD2==4] <- 2
dta157$HEALTH[dta157$QD2==5] <- 1

dta157$SAWAD <- NA
dta157$SAWADPOS <- NA
dta157$SAWADNEG <- NA
dta157$SAWADBOTH <- NA

dta157$SSTATE <- dta157$STATE
dta157$STATE <- dta157$STATE

dta157$MALE <- 1*(dta157$SEX==1)

dta157$NUMBER <- 157

dta157$MONTH <- 95

dta157$MARKET <- 0
dta157$MARKET[dta157$Q16==2] <- 1

dta157$SELFINSURE <- 0
dta157$SELFINSURE[dta157$QD4A==3]<-1
dta157$SELFINSURE[dta157$COVERED==0] <- 0

dta157$EMPLINSURE <- 0
dta157$EMPLINSURE[dta157$QD4A==1]<-1
dta157$EMPLINSURE[dta157$QD4A==2]<-1
dta157$EMPLINSURE[dta157$COVERED==0] <- 0

dta157$PREEXIST <- NA
dta157$PREEXIST[dta157$Q18=="Yes, someone in household has pre-existing condition"] <- 1
dta157$PREEXIST[dta157$Q18=="No, no one in household has pre-existing condition"] <- 0

dta157$HURT <- NA

dta157$HELPHOW <- NA

dta157$HURTHOW <- NA

#sort(table(dta157$Q2CD[dta157$FAVOR==1]))/sum(sort(table(dta157$Q2CD[dta157$FAVOR==1])))
#lout157a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta157)
#summary(#lout157a)
##mf157a <- model.frame(#lout157a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
##mf157a2 <- subsetn(dta157,select=nms)

#lout157b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta157)
#summary(#lout157b)
##mf157b <- model.frame(#lout157b)

#lout157d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta157)
#summary(#lout157d)
##fv157d <- model.frame(#lout157d)
fvnms <- c("HELPHOW","HURTHOW","HURT","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv157a2 <- subsetn(dta157,select=fvnms)

#dta157$PSRAID <- NA
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s157 <- subsetn(dta157,select=masterlist, subset=T)



##### November 2016
dta156 <- read.csv.lower("hni156.csv")

dta156$INCOME <- NA
dta156$INCOME[dta156$qd14==1] <- 10
dta156$INCOME[dta156$qd14==2] <- 25
dta156$INCOME[dta156$qd14==3] <- 35
dta156$INCOME[dta156$qd14==4] <- 45
dta156$INCOME[dta156$qd14==5] <- 62.5
dta156$INCOME[dta156$qd14==6] <- 82.5
dta156$INCOME[dta156$qd14==7] <- 95
dta156$INCOME[dta156$qd14==8] <- 200

dta156$HISP2 <- dta156$hisp
dta156$HISP[dta156$HISP2==2] <- 0
dta156$HISP[dta156$HISP2==9] <- 0
dta156$HISP[dta156$HISP2==1] <- 1

dta156$EDUC <- NA
dta156$EDUC[dta156$educ2==1] <- 6
dta156$EDUC[dta156$educ2==2] <- 10
dta156$EDUC[dta156$educ2==3] <- 12
dta156$EDUC[dta156$educ2==4] <- 13
dta156$EDUC[dta156$educ2==5] <- 14
dta156$EDUC[dta156$educ2==6] <- 16
dta156$EDUC[dta156$educ2==7] <- 17
dta156$EDUC[dta156$educ2==8] <- 19

dta156$PID <- NA
dta156$PID[dta156$qd8==2] <- 1
dta156$PID[dta156$qd8>=3 & dta156$qd8<=4] <- 2
dta156$PID[dta156$qd8==1] <- 3

dta156$PID5 <- NA
dta156$PID5[dta156$PID==1] <- 1
dta156$PID5[dta156$qd8a==1] <- 2
dta156$PID5[dta156$qd8a %in%  c(3, 4, 9)] <- 3
dta156$PID5[dta156$qd8a==2] <- 4
dta156$PID5[dta156$PID==3] <- 5

dta156$REGISTERED <- NA
dta156$REGISTERED[dta156$q1=="Yes"] <- 1
dta156$REGISTERED[dta156$q1=="No"] <- 2

dta156$BETPER <- NA
dta156$BETPER[dta156$q6a=="Better off"] <- 3
dta156$BETPER[dta156$q6a=="It won't make much difference"] <- 2
dta156$BETPER[dta156$q6a=="(DO NOT READ) Don't know/Refused"] <- 2
dta156$BETPER[dta156$q6a=="Worse off"] <- 1

dta156$BETCOU <- NA
dta156$BETCOU[dta156$q6b=="Better off"] <- 3
dta156$BETCOU[dta156$q6b=="It won't make much difference"] <- 2
dta156$BETCOU[dta156$q6b=="(DO NOT READ) Don't know/Refused"] <- 2
dta156$BETCOU[dta156$q6b=="Worse off"] <- 1

# NOTE: var replaced with FAVOR var.
dta156$SUPPORT <- NA
#dta156$SUPPORT[dta156$Q1=="Strongly support"] <- 4
#dta156$SUPPORT[dta156$Q1=="Somewhat support"] <- 3
#dta156$SUPPORT[dta156$Q1=="Somewhat oppose"] <- 2
#dta156$SUPPORT[dta156$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta156$BLACK <- (dta156$race==2)*1
dta156$ASIAN <- (dta156$race==3)*1
dta156$OTHER <- (dta156$race==4)*1

dta156$AGE <- dta156$age
dta156$AGE[dta156$AGE==99] <- NA
dta156$MEDICARE <- (dta156$AGE > 64)*1


dta156$COVERED <- (dta156$qd4==1)*1


dta156$IDEO <- NA
dta156$IDEO[dta156$qd8b==1] <- 3
dta156$IDEO[dta156$qd8b==2] <- 2
dta156$IDEO[dta156$qd8b==3] <- 1

dta156$FAVOR <- NA
dta156$FAVOR[dta156$q5==1] <- 4
dta156$FAVOR[dta156$q5==2] <- 3
dta156$FAVOR[dta156$q5==3] <- 2
dta156$FAVOR[dta156$q5==4] <- 1

# Question Still Not Asked
dta156$SELFEMPLOY <- NA
#dta156$SELFEMPLOY[dta156$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta156$RETIRED <- 0
dta156$RETIRED[dta156$qd3==6] <- 1

dta156$MEDICARESR <- 0
dta156$MEDICARESR <- 1*(dta156$qd4a==4)
dta156$MEDICARESR[dta156$COVERED==0] <- 0

dta156$MEDICAID <- 0
dta156$MEDICAID <- 1*(dta156$qd4a==5)
dta156$MEDICAID[dta156$COVERED==0] <- 0


dta156$HEALTH <- NA
dta156$HEALTH[dta156$qd2==1] <- 5
dta156$HEALTH[dta156$qd2==2] <- 4
dta156$HEALTH[dta156$qd2==3] <- 3
dta156$HEALTH[dta156$qd2==4] <- 2
dta156$HEALTH[dta156$qd2==5] <- 1

dta156$SAWAD <- NA
dta156$SAWADPOS <- NA
dta156$SAWADNEG <- NA
dta156$SAWADBOTH <- NA

dta156$SSTATE <- dta156$state
dta156$STATE <- dta156$state

dta156$MALE <- 1*(dta156$sex==1)

dta156$NUMBER <- 156

dta156$MONTH <- 94


dta156$MARKET <- 0
dta156$MARKET[dta156$q16==2] <- 1

#dta156$MARKET <- NA

dta156$SELFINSURE <- 0
dta156$SELFINSURE[dta156$qd4a==3]<-1
dta156$SELFINSURE[dta156$COVERED==0] <- 0

dta156$EMPLINSURE <- 0
dta156$EMPLINSURE[dta156$qd4a==1]<-1
dta156$EMPLINSURE[dta156$qd4a==2]<-1
dta156$EMPLINSURE[dta156$COVERED==0] <- 0

dta156$PREEXIST <- NA
dta156$PREEXIST[dta156$q26=="Yes, someone in household has pre-existing condition"] <- 1
dta156$PREEXIST[dta156$q26=="No, no one in household has pre-existing condition"] <- 0

dta156$HURT <- NA

dta156$HELPHOW <- NA

dta156$HURTHOW <- NA

#sort(table(dta156$Q2CD[dta156$FAVOR==1]))/sum(sort(table(dta156$Q2CD[dta156$FAVOR==1])))

#lout156a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta156)
#summary(#lout156a)
##mf156a <- model.frame(#lout156a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
##mf156a2 <- subsetn(dta156,select=nms)

#lout156b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta156)
#summary(#lout156b)
##mf156b <- model.frame(#lout156b)

#lout156d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta156)
#summary(#lout156d)
##fv156d <- model.frame(#lout156d)
fvnms <- c("HELPHOW","HURTHOW","HURT","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv156a2 <- subsetn(dta156,select=fvnms)

dta156$PSRAID <- dta156$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s156 <- subsetn(dta156,select=masterlist, subset=T)




################## works below
##### October 2016
dta155 <- read.csv.lower("hni155.csv")

dta155$INCOME <- NA
dta155$INCOME[dta155$qd14==1] <- 10
dta155$INCOME[dta155$qd14==2] <- 25
dta155$INCOME[dta155$qd14==3] <- 35
dta155$INCOME[dta155$qd14==4] <- 45
dta155$INCOME[dta155$qd14==5] <- 62.5
dta155$INCOME[dta155$qd14==6] <- 82.5
dta155$INCOME[dta155$qd14==7] <- 95
dta155$INCOME[dta155$qd14==8] <- 200

dta155$HISP2 <- dta155$hisp
dta155$HISP[dta155$HISP2==2] <- 0
dta155$HISP[dta155$HISP2==9] <- 0
dta155$HISP[dta155$HISP2==1] <- 1

dta155$EDUC <- NA
dta155$EDUC[dta155$educ2==1] <- 6
dta155$EDUC[dta155$educ2==2] <- 10
dta155$EDUC[dta155$educ2==3] <- 12
dta155$EDUC[dta155$educ2==4] <- 13
dta155$EDUC[dta155$educ2==5] <- 14
dta155$EDUC[dta155$educ2==6] <- 16
dta155$EDUC[dta155$educ2==7] <- 17
dta155$EDUC[dta155$educ2==8] <- 19

dta155$PID <- NA
dta155$PID[dta155$qd8==2] <- 1
dta155$PID[dta155$qd8>=3 & dta155$qd8<=4] <- 2
dta155$PID[dta155$qd8==1] <- 3

dta155$PID5 <- NA
dta155$PID5[dta155$PID==1] <- 1
dta155$PID5[dta155$qd8a==1] <- 2
dta155$PID5[dta155$qd8a %in%  c(3, 4, 9)] <- 3
dta155$PID5[dta155$qd8a==2] <- 4
dta155$PID5[dta155$PID==3] <- 5

dta155$REGISTERED <- NA
dta155$REGISTERED[dta155$QD9=="Yes"] <- 1
dta155$REGISTERED[dta155$QD9=="No"] <- 2

dta155$BETPER <- NA
dta155$BETPER[dta155$Q4A=="Better off"] <- 3
dta155$BETPER[dta155$Q4A=="It won't make much difference"] <- 2
dta155$BETPER[dta155$Q4A=="(DO NOT READ) Don't know/Refused"] <- 2
dta155$BETPER[dta155$Q4A=="Worse off"] <- 1

dta155$BETCOU <- NA
dta155$BETCOU[dta155$Q4B=="Better off"] <- 3
dta155$BETCOU[dta155$Q4B=="It won't make much difference"] <- 2
dta155$BETCOU[dta155$Q4B=="(DO NOT READ) Don't know/Refused"] <- 2
dta155$BETCOU[dta155$Q4B=="Worse off"] <- 1

# NOTE: var replaced with FAVOR var.
dta155$SUPPORT <- NA
#dta155$SUPPORT[dta155$Q1=="Strongly support"] <- 4
#dta155$SUPPORT[dta155$Q1=="Somewhat support"] <- 3
#dta155$SUPPORT[dta155$Q1=="Somewhat oppose"] <- 2
#dta155$SUPPORT[dta155$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta155$BLACK <- (dta155$race==2)*1
dta155$ASIAN <- (dta155$race==3)*1
dta155$OTHER <- (dta155$race==4)*1

dta155$AGE <- dta155$age
dta155$AGE[dta155$AGE==99] <- NA
dta155$MEDICARE <- (dta155$AGE > 64)*1


dta155$COVERED <- (dta155$qd4==1)*1


dta155$IDEO <- NA
dta155$IDEO[dta155$qd8b==1] <- 3
dta155$IDEO[dta155$qd8b==2] <- 2
dta155$IDEO[dta155$qd8b==3] <- 1

dta155$FAVOR <- NA
dta155$FAVOR[dta155$q2==1] <- 4
dta155$FAVOR[dta155$q2==2] <- 3
dta155$FAVOR[dta155$q2==3] <- 2
dta155$FAVOR[dta155$q2==4] <- 1

# Question Still Not Asked
dta155$SELFEMPLOY <- NA
#dta155$SELFEMPLOY[dta155$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta155$RETIRED <- 0
dta155$RETIRED[dta155$qd3==6] <- 1

dta155$MEDICARESR <- 0
dta155$MEDICARESR <- 1*(dta155$qd4a==4)
dta155$MEDICARESR[dta155$COVERED==0] <- 0

dta155$MEDICAID <- 0
dta155$MEDICAID <- 1*(dta155$qd4a==5)
dta155$MEDICAID[dta155$COVERED==0] <- 0


dta155$HEALTH <- NA
dta155$HEALTH[dta155$qd2==1] <- 5
dta155$HEALTH[dta155$qd2==2] <- 4
dta155$HEALTH[dta155$qd2==3] <- 3
dta155$HEALTH[dta155$qd2==4] <- 2
dta155$HEALTH[dta155$qd2==5] <- 1

dta155$SAWAD <- NA
dta155$SAWADPOS <- NA
dta155$SAWADNEG <- NA
dta155$SAWADBOTH <- NA

dta155$SSTATE <- dta155$state
dta155$STATE <- dta155$state

dta155$MALE <- 1*(dta155$sex==1)

dta155$NUMBER <- 155

dta155$MONTH <- 93

dta155$MARKET <- NA

dta155$SELFINSURE <- 0
dta155$SELFINSURE[dta155$qd4a==3]<-1
dta155$SELFINSURE[dta155$COVERED==0] <- 0

dta155$EMPLINSURE <- 0
dta155$EMPLINSURE[dta155$qd4a==1]<-1
dta155$EMPLINSURE[dta155$qd4a==2]<-1
dta155$EMPLINSURE[dta155$COVERED==0] <- 0

dta155$PREEXIST <- NA

#sort(table(dta155$Q2CD[dta155$FAVOR==1]))/sum(sort(table(dta155$Q2CD[dta155$FAVOR==1])))

#lout155a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta155)
#summary(#lout155a)
##mf155a <- model.frame(#lout155a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
##mf155a2 <- subsetn(dta155,select=nms)

#lout155b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta155)
#summary(#lout155b)
##mf155b <- model.frame(#lout155b)

#lout155d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta155)
#summary(#lout155d)
##fv155d <- model.frame(#lout155d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv155a2 <- subsetn(dta155,select=fvnms)

dta155$PSRAID <- dta155$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s155 <- subsetn(dta155,select=masterlist, subset=T)



##### September 2016
dta154 <- read.csv.lower("hni154.csv")

dta154$INCOME <- NA
dta154$INCOME[dta154$qd14==1] <- 10
dta154$INCOME[dta154$qd14==2] <- 25
dta154$INCOME[dta154$qd14==3] <- 35
dta154$INCOME[dta154$qd14==4] <- 45
dta154$INCOME[dta154$qd14==5] <- 62.5
dta154$INCOME[dta154$qd14==6] <- 82.5
dta154$INCOME[dta154$qd14==7] <- 95
dta154$INCOME[dta154$qd14==8] <- 200

dta154$HISP2 <- dta154$hisp
dta154$HISP[dta154$HISP2==2] <- 0
dta154$HISP[dta154$HISP2==9] <- 0
dta154$HISP[dta154$HISP2==1] <- 1

dta154$EDUC <- NA
dta154$EDUC[dta154$educ2==1] <- 6
dta154$EDUC[dta154$educ2==2] <- 10
dta154$EDUC[dta154$educ2==3] <- 12
dta154$EDUC[dta154$educ2==4] <- 13
dta154$EDUC[dta154$educ2==5] <- 14
dta154$EDUC[dta154$educ2==6] <- 16
dta154$EDUC[dta154$educ2==7] <- 17
dta154$EDUC[dta154$educ2==8] <- 19

dta154$PID <- NA
dta154$PID[dta154$qd8==2] <- 1
dta154$PID[dta154$qd8>=3 & dta154$qd8<=4] <- 2
dta154$PID[dta154$qd8==1] <- 3

dta154$PID5 <- NA
dta154$PID5[dta154$PID==1] <- 1
dta154$PID5[dta154$qd8a==1] <- 2
dta154$PID5[dta154$qd8a %in%  c(3, 4, 9)] <- 3
dta154$PID5[dta154$qd8a==2] <- 4
dta154$PID5[dta154$PID==3] <- 5

dta154$REGISTERED <- NA
dta154$REGISTERED[dta154$QD9=="Yes"] <- 1
dta154$REGISTERED[dta154$QD9=="No"] <- 2


dta154$BETPER <- NA

dta154$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta154$SUPPORT <- NA
#dta154$SUPPORT[dta154$Q1=="Strongly support"] <- 4
#dta154$SUPPORT[dta154$Q1=="Somewhat support"] <- 3
#dta154$SUPPORT[dta154$Q1=="Somewhat oppose"] <- 2
#dta154$SUPPORT[dta154$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta154$BLACK <- (dta154$race==2)*1
dta154$ASIAN <- (dta154$race==3)*1
dta154$OTHER <- (dta154$race==4)*1

dta154$AGE <- dta154$age
dta154$AGE[dta154$AGE==99] <- NA
dta154$MEDICARE <- (dta154$AGE > 64)*1


dta154$COVERED <- (dta154$qd4==1)*1


dta154$IDEO <- NA
dta154$IDEO[dta154$qd8b==1] <- 3
dta154$IDEO[dta154$qd8b==2] <- 2
dta154$IDEO[dta154$qd8b==3] <- 1

dta154$FAVOR <- NA
dta154$FAVOR[dta154$q3==1] <- 4
dta154$FAVOR[dta154$q3==2] <- 3
dta154$FAVOR[dta154$q3==3] <- 2
dta154$FAVOR[dta154$q3==4] <- 1

# Question Still Not Asked
dta154$SELFEMPLOY <- NA
#dta154$SELFEMPLOY[dta154$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta154$RETIRED <- 0
dta154$RETIRED[dta154$qd3==6] <- 1

dta154$MEDICARESR <- 0
dta154$MEDICARESR <- 1*(dta154$qd4a==4)
dta154$MEDICARESR[dta154$COVERED==0] <- 0

dta154$MEDICAID <- 0
dta154$MEDICAID <- 1*(dta154$qd4a==5)
dta154$MEDICAID[dta154$COVERED==0] <- 0


dta154$HEALTH <- NA
dta154$HEALTH[dta154$qd2==1] <- 5
dta154$HEALTH[dta154$qd2==2] <- 4
dta154$HEALTH[dta154$qd2==3] <- 3
dta154$HEALTH[dta154$qd2==4] <- 2
dta154$HEALTH[dta154$qd2==5] <- 1

dta154$SAWAD <- NA
dta154$SAWADPOS <- NA
dta154$SAWADNEG <- NA
dta154$SAWADBOTH <- NA

dta154$SSTATE <- dta154$state
dta154$STATE <- dta154$state

dta154$MALE <- 1*(dta154$sex==1)

dta154$NUMBER <- 154

dta154$MONTH <- 92

dta154$MARKET <- NA

dta154$SELFINSURE <- 0
dta154$SELFINSURE[dta154$qd4a==3]<-1
dta154$SELFINSURE[dta154$COVERED==0] <- 0

dta154$EMPLINSURE <- 0
dta154$EMPLINSURE[dta154$qd4a==1]<-1
dta154$EMPLINSURE[dta154$qd4a==2]<-1
dta154$EMPLINSURE[dta154$COVERED==0] <- 0

dta154$PREEXIST <- NA

#sort(table(dta154$Q2CD[dta154$FAVOR==1]))/sum(sort(table(dta154$Q2CD[dta154$FAVOR==1])))

#lout154a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta154)
#summary(#lout154a)
##mf154a <- model.frame(#lout154a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf154a2 <- subsetn(dta154,select=nms)

#lout154b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta154)
#summary(#lout154b)
##mf154b <- model.frame(#lout154b)

#lout154d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta154)
#summary(#lout154d)
##fv154d <- model.frame(#lout154d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv154a2 <- subsetn(dta154,select=fvnms)

dta154$PSRAID <- dta154$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s154 <- subsetn(dta154,select=masterlist, subset=T)



##### August 2016
dta153 <- read.csv.lower("hni153.csv")

dta153$INCOME <- NA
dta153$INCOME[dta153$qd14==1] <- 10
dta153$INCOME[dta153$qd14==2] <- 25
dta153$INCOME[dta153$qd14==3] <- 35
dta153$INCOME[dta153$qd14==4] <- 45
dta153$INCOME[dta153$qd14==5] <- 62.5
dta153$INCOME[dta153$qd14==6] <- 82.5
dta153$INCOME[dta153$qd14==7] <- 95
dta153$INCOME[dta153$qd14==8] <- 200

dta153$HISP2 <- dta153$hisp
dta153$HISP[dta153$HISP2==2] <- 0
dta153$HISP[dta153$HISP2==9] <- 0
dta153$HISP[dta153$HISP2==1] <- 1

dta153$EDUC <- NA
dta153$EDUC[dta153$educ2==1] <- 6
dta153$EDUC[dta153$educ2==2] <- 10
dta153$EDUC[dta153$educ2==3] <- 12
dta153$EDUC[dta153$educ2==4] <- 13
dta153$EDUC[dta153$educ2==5] <- 14
dta153$EDUC[dta153$educ2==6] <- 16
dta153$EDUC[dta153$educ2==7] <- 17
dta153$EDUC[dta153$educ2==8] <- 19

dta153$PID <- NA
dta153$PID[dta153$qd8==2] <- 1
dta153$PID[dta153$qd8>=3 & dta153$qd8<=4] <- 2
dta153$PID[dta153$qd8==1] <- 3

dta153$PID5 <- NA
dta153$PID5[dta153$PID==1] <- 1
dta153$PID5[dta153$qd8a==1] <- 2
dta153$PID5[dta153$qd8a %in%  c(3, 4, 9)] <- 3
dta153$PID5[dta153$qd8a==2] <- 4
dta153$PID5[dta153$PID==3] <- 5

dta153$REGISTERED <- NA
dta153$REGISTERED[dta153$QD9=="Yes"] <- 1
dta153$REGISTERED[dta153$QD9=="No"] <- 2

dta153$BETPER <- NA

dta153$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta153$SUPPORT <- NA
#dta153$SUPPORT[dta153$Q1=="Strongly support"] <- 4
#dta153$SUPPORT[dta153$Q1=="Somewhat support"] <- 3
#dta153$SUPPORT[dta153$Q1=="Somewhat oppose"] <- 2
#dta153$SUPPORT[dta153$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta153$BLACK <- (dta153$race==2)*1
dta153$ASIAN <- (dta153$race==3)*1
dta153$OTHER <- (dta153$race==4)*1

dta153$AGE <- dta153$age
dta153$AGE[dta153$AGE==99] <- NA
dta153$MEDICARE <- (dta153$AGE > 64)*1


dta153$COVERED <- (dta153$qd4==1)*1


dta153$IDEO <- NA
dta153$IDEO[dta153$qd8b==1] <- 3
dta153$IDEO[dta153$qd8b==2] <- 2
dta153$IDEO[dta153$qd8b==3] <- 1

dta153$FAVOR <- NA
dta153$FAVOR[dta153$q1==1] <- 4
dta153$FAVOR[dta153$q1==2] <- 3
dta153$FAVOR[dta153$q1==3] <- 2
dta153$FAVOR[dta153$q1==4] <- 1

# Question Still Not Asked
dta153$SELFEMPLOY <- NA
#dta153$SELFEMPLOY[dta153$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta153$RETIRED <- 0
dta153$RETIRED[dta153$qd3==6] <- 1

dta153$MEDICARESR <- 0
dta153$MEDICARESR <- 1*(dta153$qd4a==4)
dta153$MEDICARESR[dta153$COVERED==0] <- 0

dta153$MEDICAID <- 0
dta153$MEDICAID <- 1*(dta153$qd4a==5)
dta153$MEDICAID[dta153$COVERED==0] <- 0


dta153$HEALTH <- NA
dta153$HEALTH[dta153$qd2==1] <- 5
dta153$HEALTH[dta153$qd2==2] <- 4
dta153$HEALTH[dta153$qd2==3] <- 3
dta153$HEALTH[dta153$qd2==4] <- 2
dta153$HEALTH[dta153$qd2==5] <- 1

dta153$SAWAD <- NA
dta153$SAWADPOS <- NA
dta153$SAWADNEG <- NA
dta153$SAWADBOTH <- NA

dta153$SSTATE <- dta153$state
dta153$STATE <- dta153$state

dta153$MALE <- 1*(dta153$sex==1)

dta153$NUMBER <- 153

dta153$MONTH <- 91

dta153$MARKET <- NA

dta153$SELFINSURE <- 0
dta153$SELFINSURE[dta153$qd4a==3]<-1
dta153$SELFINSURE[dta153$COVERED==0] <- 0

dta153$EMPLINSURE <- 0
dta153$EMPLINSURE[dta153$qd4a==1]<-1
dta153$EMPLINSURE[dta153$qd4a==2]<-1
dta153$EMPLINSURE[dta153$COVERED==0] <- 0

dta153$PREEXIST <- NA
dta153$PREEXIST[dta153$Q26=="Yes, someone in household has pre-existing condition"] <- 1
dta153$PREEXIST[dta153$Q26=="No, no one in household has pre-existing condition"] <- 0

#sort(table(dta153$Q2CD[dta153$FAVOR==1]))/sum(sort(table(dta153$Q2CD[dta153$FAVOR==1])))

#lout153a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta153)
#summary(#lout153a)
##mf153a <- model.frame(#lout153a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf153a2 <- subsetn(dta153,select=nms)

#lout153b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta153)
#summary(#lout153b)
##mf153b <- model.frame(#lout153b)

#lout153d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta153)
#summary(#lout153d)
##fv153d <- model.frame(#lout153d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv153a2 <- subsetn(dta153,select=fvnms)

dta153$PSRAID <- dta153$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s153 <- subsetn(dta153,select=masterlist, subset=T)



##### July 2016
dta152 <- read.csv.lower("hni152.csv")

dta152$INCOME <- NA
dta152$INCOME[dta152$qd14==1] <- 10
dta152$INCOME[dta152$qd14==2] <- 25
dta152$INCOME[dta152$qd14==3] <- 35
dta152$INCOME[dta152$qd14==4] <- 45
dta152$INCOME[dta152$qd14==5] <- 62.5
dta152$INCOME[dta152$qd14==6] <- 82.5
dta152$INCOME[dta152$qd14==7] <- 95
dta152$INCOME[dta152$qd14==8] <- 200

dta152$HISP2 <- dta152$hisp
dta152$HISP[dta152$HISP2==2] <- 0
dta152$HISP[dta152$HISP2==9] <- 0
dta152$HISP[dta152$HISP2==1] <- 1

dta152$EDUC <- NA
dta152$EDUC[dta152$educ2==1] <- 6
dta152$EDUC[dta152$educ2==2] <- 10
dta152$EDUC[dta152$educ2==3] <- 12
dta152$EDUC[dta152$educ2==4] <- 13
dta152$EDUC[dta152$educ2==5] <- 14
dta152$EDUC[dta152$educ2==6] <- 16
dta152$EDUC[dta152$educ2==7] <- 17
dta152$EDUC[dta152$educ2==8] <- 19

dta152$PID <- NA
dta152$PID[dta152$qd8==2] <- 1
dta152$PID[dta152$qd8>=3 & dta152$qd8<=4] <- 2
dta152$PID[dta152$qd8==1] <- 3

dta152$PID5 <- NA
dta152$PID5[dta152$PID==1] <- 1
dta152$PID5[dta152$qd8a==1] <- 2
dta152$PID5[dta152$qd8a %in%  c(3, 4, 9)] <- 3
dta152$PID5[dta152$qd8a==2] <- 4
dta152$PID5[dta152$PID==3] <- 5

dta152$REGISTERED <- NA
dta152$REGISTERED[dta152$QD9=="Yes"] <- 1
dta152$REGISTERED[dta152$QD9=="No"] <- 2


dta152$BETPER <- NA

dta152$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta152$SUPPORT <- NA
#dta152$SUPPORT[dta152$Q1=="Strongly support"] <- 4
#dta152$SUPPORT[dta152$Q1=="Somewhat support"] <- 3
#dta152$SUPPORT[dta152$Q1=="Somewhat oppose"] <- 2
#dta152$SUPPORT[dta152$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta152$BLACK <- (dta152$race==2)*1
dta152$ASIAN <- (dta152$race==3)*1
dta152$OTHER <- (dta152$race==4)*1

dta152$AGE <- dta152$age
dta152$AGE[dta152$AGE==99] <- NA
dta152$MEDICARE <- (dta152$AGE > 64)*1


dta152$COVERED <- (dta152$qd4==1)*1


dta152$IDEO <- NA
dta152$IDEO[dta152$qd8b==1] <- 3
dta152$IDEO[dta152$qd8b==2] <- 2
dta152$IDEO[dta152$qd8b==3] <- 1

dta152$FAVOR <- NA
dta152$FAVOR[dta152$q3==1] <- 4
dta152$FAVOR[dta152$q3==2] <- 3
dta152$FAVOR[dta152$q3==3] <- 2
dta152$FAVOR[dta152$q3==4] <- 1

# Question Still Not Asked
dta152$SELFEMPLOY <- NA
#dta152$SELFEMPLOY[dta152$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta152$RETIRED <- 0
dta152$RETIRED[dta152$qd3==6] <- 1

dta152$MEDICARESR <- 0
dta152$MEDICARESR <- 1*(dta152$qd4a==4)
dta152$MEDICARESR[dta152$COVERED==0] <- 0

dta152$MEDICAID <- 0
dta152$MEDICAID <- 1*(dta152$qd4a==5)
dta152$MEDICAID[dta152$COVERED==0] <- 0


dta152$HEALTH <- NA
dta152$HEALTH[dta152$qd2==1] <- 5
dta152$HEALTH[dta152$qd2==2] <- 4
dta152$HEALTH[dta152$qd2==3] <- 3
dta152$HEALTH[dta152$qd2==4] <- 2
dta152$HEALTH[dta152$qd2==5] <- 1

dta152$SAWAD <- NA
dta152$SAWADPOS <- NA
dta152$SAWADNEG <- NA
dta152$SAWADBOTH <- NA

dta152$SSTATE <- dta152$state
dta152$STATE <- dta152$state

dta152$MALE <- 1*(dta152$sex==1)

dta152$NUMBER <- 152

dta152$MONTH <- 90

dta152$MARKET <- NA

dta152$SELFINSURE <- 0
dta152$SELFINSURE[dta152$qd4a==3]<-1
dta152$SELFINSURE[dta152$COVERED==0] <- 0

dta152$EMPLINSURE <- 0
dta152$EMPLINSURE[dta152$qd4a==1]<-1
dta152$EMPLINSURE[dta152$qd4a==2]<-1
dta152$EMPLINSURE[dta152$COVERED==0] <- 0

dta152$PREEXIST <- NA

#sort(table(dta152$Q2CD[dta152$FAVOR==1]))/sum(sort(table(dta152$Q2CD[dta152$FAVOR==1])))

#lout152a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta152)
#summary(#lout152a)
##mf152a <- model.frame(#lout152a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf152a2 <- subsetn(dta152,select=nms)

#lout152b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta152)
#summary(#lout152b)
##mf152b <- model.frame(#lout152b)

#lout152d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta152)
#summary(#lout152d)
##fv152d <- model.frame(#lout152d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv152a2 <- subsetn(dta152,select=fvnms)

dta152$PSRAID <- dta152$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s152 <- subsetn(dta152,select=masterlist, subset=T)





##### June 2016
dta151 <- read.csv.lower("hni151.csv")

dta151$INCOME <- NA
dta151$INCOME[dta151$qd14==1] <- 10
dta151$INCOME[dta151$qd14==2] <- 25
dta151$INCOME[dta151$qd14==3] <- 35
dta151$INCOME[dta151$qd14==4] <- 45
dta151$INCOME[dta151$qd14==5] <- 62.5
dta151$INCOME[dta151$qd14==6] <- 82.5
dta151$INCOME[dta151$qd14==7] <- 95
dta151$INCOME[dta151$qd14==8] <- 200

dta151$HISP2 <- dta151$hisp
dta151$HISP[dta151$HISP2==2] <- 0
dta151$HISP[dta151$HISP2==9] <- 0
dta151$HISP[dta151$HISP2==1] <- 1

dta151$EDUC <- NA
dta151$EDUC[dta151$educ2==1] <- 6
dta151$EDUC[dta151$educ2==2] <- 10
dta151$EDUC[dta151$educ2==3] <- 12
dta151$EDUC[dta151$educ2==4] <- 13
dta151$EDUC[dta151$educ2==5] <- 14
dta151$EDUC[dta151$educ2==6] <- 16
dta151$EDUC[dta151$educ2==7] <- 17
dta151$EDUC[dta151$educ2==8] <- 19

dta151$PID <- NA
dta151$PID[dta151$qd8==2] <- 1
dta151$PID[dta151$qd8>=3 & dta151$qd8<=4] <- 2
dta151$PID[dta151$qd8==1] <- 3

dta151$PID5 <- NA
dta151$PID5[dta151$PID==1] <- 1
dta151$PID5[dta151$qd8a==1] <- 2
dta151$PID5[dta151$qd8a %in%  c(3, 4, 9)] <- 3
dta151$PID5[dta151$qd8a==2] <- 4
dta151$PID5[dta151$PID==3] <- 5

dta151$REGISTERED <- NA
dta151$REGISTERED[dta151$QD9=="Yes"] <- 1
dta151$REGISTERED[dta151$QD9=="No"] <- 2

dta151$BETPER <- NA

dta151$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta151$SUPPORT <- NA
#dta151$SUPPORT[dta151$Q1=="Strongly support"] <- 4
#dta151$SUPPORT[dta151$Q1=="Somewhat support"] <- 3
#dta151$SUPPORT[dta151$Q1=="Somewhat oppose"] <- 2
#dta151$SUPPORT[dta151$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta151$BLACK <- (dta151$race==2)*1
dta151$ASIAN <- (dta151$race==3)*1
dta151$OTHER <- (dta151$race==4)*1

dta151$AGE <- dta151$age
dta151$AGE[dta151$AGE==99] <- NA
dta151$MEDICARE <- (dta151$AGE > 64)*1


dta151$COVERED <- (dta151$qd4==1)*1


dta151$IDEO <- NA
dta151$IDEO[dta151$qd8b==1] <- 3
dta151$IDEO[dta151$qd8b==2] <- 2
dta151$IDEO[dta151$qd8b==3] <- 1

dta151$FAVOR <- NA
dta151$FAVOR[dta151$q1==1] <- 4
dta151$FAVOR[dta151$q1==2] <- 3
dta151$FAVOR[dta151$q1==3] <- 2
dta151$FAVOR[dta151$q1==4] <- 1

# Question Still Not Asked
dta151$SELFEMPLOY <- NA
#dta151$SELFEMPLOY[dta151$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta151$RETIRED <- 0
dta151$RETIRED[dta151$qd3==6] <- 1

dta151$MEDICARESR <- 0
dta151$MEDICARESR <- 1*(dta151$qd4a==4)
dta151$MEDICARESR[dta151$COVERED==0] <- 0

dta151$MEDICAID <- 0
dta151$MEDICAID <- 1*(dta151$qd4a==5)
dta151$MEDICAID[dta151$COVERED==0] <- 0


dta151$HEALTH <- NA
dta151$HEALTH[dta151$qd2==1] <- 5
dta151$HEALTH[dta151$qd2==2] <- 4
dta151$HEALTH[dta151$qd2==3] <- 3
dta151$HEALTH[dta151$qd2==4] <- 2
dta151$HEALTH[dta151$qd2==5] <- 1

dta151$SAWAD <- NA
dta151$SAWADPOS <- NA
dta151$SAWADNEG <- NA
dta151$SAWADBOTH <- NA

dta151$SSTATE <- dta151$state
dta151$STATE <- dta151$state

dta151$MALE <- 1*(dta151$sex==1)

dta151$NUMBER <- 151

dta151$MONTH <- 89

dta151$MARKET <- 0
dta151$MARKET[dta151$q27==2]<-1

dta151$SELFINSURE <- 0
dta151$SELFINSURE[dta151$qd4a==3]<-1
dta151$SELFINSURE[dta151$COVERED==0] <- 0

dta151$EMPLINSURE <- 0
dta151$EMPLINSURE[dta151$qd4a==1]<-1
dta151$EMPLINSURE[dta151$qd4a==2]<-1
dta151$EMPLINSURE[dta151$COVERED==0] <- 0

dta151$PREEXIST <- NA

#sort(table(dta151$Q2CD[dta151$FAVOR==1]))/sum(sort(table(dta151$Q2CD[dta151$FAVOR==1])))

#lout151a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta151)
#summary(#lout151a)
##mf151a <- model.frame(#lout151a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf151a2 <- subsetn(dta151,select=nms)

#lout151b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta151)
#summary(#lout151b)
##mf151b <- model.frame(#lout151b)

#lout151d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta151)
#summary(#lout151d)
##fv151d <- model.frame(#lout151d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv151a2 <- subsetn(dta151,select=fvnms)

dta151$PSRAID <- dta151$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s151 <- subsetn(dta151,select=masterlist, subset=T)



##### April 2016
dta150 <- read.csv.lower("hni150.csv")

dta150$INCOME <- NA
dta150$INCOME[dta150$qd14==1] <- 10
dta150$INCOME[dta150$qd14==2] <- 25
dta150$INCOME[dta150$qd14==3] <- 35
dta150$INCOME[dta150$qd14==4] <- 45
dta150$INCOME[dta150$qd14==5] <- 62.5
dta150$INCOME[dta150$qd14==6] <- 82.5
dta150$INCOME[dta150$qd14==7] <- 95
dta150$INCOME[dta150$qd14==8] <- 200

dta150$HISP2 <- dta150$hisp
dta150$HISP[dta150$HISP2==2] <- 0
dta150$HISP[dta150$HISP2==9] <- 0
dta150$HISP[dta150$HISP2==1] <- 1

dta150$EDUC <- NA
dta150$EDUC[dta150$educ2==1] <- 6
dta150$EDUC[dta150$educ2==2] <- 10
dta150$EDUC[dta150$educ2==3] <- 12
dta150$EDUC[dta150$educ2==4] <- 13
dta150$EDUC[dta150$educ2==5] <- 14
dta150$EDUC[dta150$educ2==6] <- 16
dta150$EDUC[dta150$educ2==7] <- 17
dta150$EDUC[dta150$educ2==8] <- 19

dta150$PID <- NA
dta150$PID[dta150$qd8==2] <- 1
dta150$PID[dta150$qd8>=3 & dta150$qd8<=4] <- 2
dta150$PID[dta150$qd8==1] <- 3

dta150$PID5 <- NA
dta150$PID5[dta150$PID==1] <- 1
dta150$PID5[dta150$qd8a==1] <- 2
dta150$PID5[dta150$qd8a %in%  c(3, 4, 9)] <- 3
dta150$PID5[dta150$qd8a==2] <- 4
dta150$PID5[dta150$PID==3] <- 5

dta150$REGISTERED <- NA
dta150$REGISTERED[dta150$QD9=="Yes"] <- 1
dta150$REGISTERED[dta150$QD9=="No"] <- 2

dta150$BETPER <- NA

dta150$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta150$SUPPORT <- NA
#dta150$SUPPORT[dta150$Q1=="Strongly support"] <- 4
#dta150$SUPPORT[dta150$Q1=="Somewhat support"] <- 3
#dta150$SUPPORT[dta150$Q1=="Somewhat oppose"] <- 2
#dta150$SUPPORT[dta150$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta150$BLACK <- (dta150$race==2)*1
dta150$ASIAN <- (dta150$race==3)*1
dta150$OTHER <- (dta150$race==4)*1

dta150$AGE <- dta150$age
dta150$AGE[dta150$AGE==99] <- NA
dta150$MEDICARE <- (dta150$AGE > 64)*1


dta150$COVERED <- (dta150$qd4==1)*1


dta150$IDEO <- NA
dta150$IDEO[dta150$qd8b==1] <- 3
dta150$IDEO[dta150$qd8b==2] <- 2
dta150$IDEO[dta150$qd8b==3] <- 1

dta150$FAVOR <- NA
dta150$FAVOR[dta150$q3==1] <- 4
dta150$FAVOR[dta150$q3==2] <- 3
dta150$FAVOR[dta150$q3==3] <- 2
dta150$FAVOR[dta150$q3==4] <- 1

# Question Still Not Asked
dta150$SELFEMPLOY <- NA
#dta150$SELFEMPLOY[dta150$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta150$RETIRED <- 0
dta150$RETIRED[dta150$qd3==6] <- 1

dta150$MEDICARESR <- 0
dta150$MEDICARESR <- 1*(dta150$qd4a==4)
dta150$MEDICARESR[dta150$COVERED==0] <- 0

dta150$MEDICAID <- 0
dta150$MEDICAID <- 1*(dta150$qd4a==5)
dta150$MEDICAID[dta150$COVERED==0] <- 0


dta150$HEALTH <- NA
dta150$HEALTH[dta150$qd2==1] <- 5
dta150$HEALTH[dta150$qd2==2] <- 4
dta150$HEALTH[dta150$qd2==3] <- 3
dta150$HEALTH[dta150$qd2==4] <- 2
dta150$HEALTH[dta150$qd2==5] <- 1

dta150$SAWAD <- NA
dta150$SAWADPOS <- NA
dta150$SAWADNEG <- NA
dta150$SAWADBOTH <- NA

dta150$SSTATE <- dta150$state
dta150$STATE <- dta150$state

dta150$MALE <- 1*(dta150$sex==1)

dta150$NUMBER <- 150

dta150$MONTH <- 87

dta150$MARKET <- 0
dta150$MARKET[dta150$q21==2]<-1

dta150$SELFINSURE <- 0
dta150$SELFINSURE[dta150$qd4a==3]<-1
dta150$SELFINSURE[dta150$COVERED==0] <- 0

dta150$EMPLINSURE <- 0
dta150$EMPLINSURE[dta150$qd4a==1]<-1
dta150$EMPLINSURE[dta150$qd4a==2]<-1
dta150$EMPLINSURE[dta150$COVERED==0] <- 0

dta150$PREEXIST <- NA

#sort(table(dta150$Q2CD[dta150$FAVOR==1]))/sum(sort(table(dta150$Q2CD[dta150$FAVOR==1])))

#lout150a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta150)
#summary(#lout150a)
##mf150a <- model.frame(#lout150a)


dta150$PSRAID <- dta150$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s150 <- subsetn(dta150,select=masterlist, subset=T)




#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf150a2 <- subsetn(dta150,select=nms)

#lout150b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta150)
#summary(#lout150b)
##mf150b <- model.frame(#lout150b)

#lout150d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta150)
#summary(#lout150d)
##fv150d <- model.frame(#lout150d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv150a2 <- subsetn(dta150,select=fvnms)

##### March 2016
dta149 <- read.csv.lower("hni149.csv")

dta149$INCOME <- NA
dta149$INCOME[dta149$qd14==1] <- 10
dta149$INCOME[dta149$qd14==2] <- 25
dta149$INCOME[dta149$qd14==3] <- 35
dta149$INCOME[dta149$qd14==4] <- 45
dta149$INCOME[dta149$qd14==5] <- 62.5
dta149$INCOME[dta149$qd14==6] <- 82.5
dta149$INCOME[dta149$qd14==7] <- 95
dta149$INCOME[dta149$qd14==8] <- 200

dta149$HISP2 <- dta149$hisp
dta149$HISP <- (dta149$HISP2==1)*1

dta149$EDUC <- NA
dta149$EDUC[dta149$educ2==1] <- 6
dta149$EDUC[dta149$educ2==2] <- 10
dta149$EDUC[dta149$educ2==3] <- 12
dta149$EDUC[dta149$educ2==4] <- 13
dta149$EDUC[dta149$educ2==5] <- 14
dta149$EDUC[dta149$educ2==6] <- 16
dta149$EDUC[dta149$educ2==7] <- 17
dta149$EDUC[dta149$educ2==8] <- 19

dta149$PID <- NA
dta149$PID[dta149$qd8==2] <- 1
dta149$PID[dta149$qd8>=3 & dta149$qd8<=4] <- 2
dta149$PID[dta149$qd8==1] <- 3

dta149$PID5 <- NA
dta149$PID5[dta149$PID==1] <- 1
dta149$PID5[dta149$qd8a==1] <- 2
dta149$PID5[dta149$qd8a %in%  c(3, 4, 9)] <- 3
dta149$PID5[dta149$qd8a==2] <- 4
dta149$PID5[dta149$PID==3] <- 5

dta149$REGISTERED <- NA
dta149$REGISTERED[dta149$QD9=="Yes"] <- 1
dta149$REGISTERED[dta149$QD9=="No"] <- 2

dta149$BETPER <- NA

dta149$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta149$SUPPORT <- NA
#dta149$SUPPORT[dta149$Q1=="Strongly support"] <- 4
#dta149$SUPPORT[dta149$Q1=="Somewhat support"] <- 3
#dta149$SUPPORT[dta149$Q1=="Somewhat oppose"] <- 2
#dta149$SUPPORT[dta149$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta149$BLACK <- (dta149$race==2)*1
dta149$ASIAN <- (dta149$race==3)*1
dta149$OTHER <- (dta149$race==4)*1

dta149$AGE <- dta149$age
dta149$AGE[dta149$AGE==99] <- NA
dta149$MEDICARE <- (dta149$AGE > 64)*1


dta149$COVERED <- (dta149$qd4==1)*1


dta149$IDEO <- NA
dta149$IDEO[dta149$qd8b==1] <- 3
dta149$IDEO[dta149$qd8b==2] <- 2
dta149$IDEO[dta149$qd8b==3] <- 1

dta149$FAVOR <- NA
dta149$FAVOR[dta149$q4==1] <- 4
dta149$FAVOR[dta149$q4==2] <- 3
dta149$FAVOR[dta149$q4==3] <- 2
dta149$FAVOR[dta149$q4==4] <- 1

# Question Still Not Asked
dta149$SELFEMPLOY <- NA
#dta149$SELFEMPLOY[dta149$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta149$RETIRED <- 0
dta149$RETIRED[dta149$qd3==6] <- 1

dta149$MEDICARESR <- 0
dta149$MEDICARESR <- 1*(dta149$qd4a==4)
dta149$MEDICARESR[dta149$COVERED==0] <- 0

dta149$MEDICAID <- 0
dta149$MEDICAID <- 1*(dta149$qd4a==5)
dta149$MEDICAID[dta149$COVERED==0] <- 0


dta149$HEALTH <- NA
dta149$HEALTH[dta149$qd2==1] <- 5
dta149$HEALTH[dta149$qd2==2] <- 4
dta149$HEALTH[dta149$qd2==3] <- 3
dta149$HEALTH[dta149$qd2==4] <- 2
dta149$HEALTH[dta149$qd2==5] <- 1

dta149$SAWAD <- NA
dta149$SAWADPOS <- NA
dta149$SAWADNEG <- NA
dta149$SAWADBOTH <- NA

dta149$SSTATE <- dta149$state
dta149$STATE <- dta149$state

dta149$MALE <- 1*(dta149$sex==1)

dta149$NUMBER <- 149

dta149$MONTH <- 86

dta149$MARKET <- 0
dta149$MARKET[dta149$q13==2]<-1

dta149$SELFINSURE <- 0
dta149$SELFINSURE[dta149$qd4a==3]<-1
dta149$SELFINSURE[dta149$COVERED==0] <- 0

dta149$EMPLINSURE <- 0
dta149$EMPLINSURE[dta149$qd4a==1]<-1
dta149$EMPLINSURE[dta149$qd4a==2]<-1
dta149$EMPLINSURE[dta149$COVERED==0] <- 0

dta149$PREEXIST <- NA

#sort(table(dta149$Q2CD[dta149$FAVOR==1]))/sum(sort(table(dta149$Q2CD[dta149$FAVOR==1])))

#lout149a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta149)
#summary(#lout149a)
##mf149a <- model.frame(#lout149a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf149a2 <- subsetn(dta149,select=nms)

#lout149b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta149)
#summary(#lout149b)
##mf149b <- model.frame(#lout149b)

#lout149d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta149)
#summary(#lout149d)
##fv149d <- model.frame(#lout149d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv149a2 <- subsetn(dta149,select=fvnms)

dta149$PSRAID <- dta149$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s149 <- subsetn(dta149,select=masterlist, subset=T)



##### February 2016
dta148 <- read.csv.lower("hni148.csv")

dta148$INCOME <- NA
dta148$INCOME[dta148$qd14==1] <- 10
dta148$INCOME[dta148$qd14==2] <- 25
dta148$INCOME[dta148$qd14==3] <- 35
dta148$INCOME[dta148$qd14==4] <- 45
dta148$INCOME[dta148$qd14==5] <- 62.5
dta148$INCOME[dta148$qd14==6] <- 82.5
dta148$INCOME[dta148$qd14==7] <- 95
dta148$INCOME[dta148$qd14==8] <- 200

dta148$HISP2 <- dta148$hisp
dta148$HISP[dta148$HISP2==2] <- 0
dta148$HISP[dta148$HISP2==9] <- 0
dta148$HISP[dta148$HISP2==1] <- 1

dta148$EDUC <- NA
dta148$EDUC[dta148$educ2==1] <- 6
dta148$EDUC[dta148$educ2==2] <- 10
dta148$EDUC[dta148$educ2==3] <- 12
dta148$EDUC[dta148$educ2==4] <- 13
dta148$EDUC[dta148$educ2==5] <- 14
dta148$EDUC[dta148$educ2==6] <- 16
dta148$EDUC[dta148$educ2==7] <- 17
dta148$EDUC[dta148$educ2==8] <- 19

dta148$PID <- NA
dta148$PID[dta148$qd8==2] <- 1
dta148$PID[dta148$qd8>=3 & dta148$qd8<=4] <- 2
dta148$PID[dta148$qd8==1] <- 3

dta148$PID5 <- NA
dta148$PID5[dta148$PID==1] <- 1
dta148$PID5[dta148$qd8a==1] <- 2
dta148$PID5[dta148$qd8a %in%  c(3, 4, 9)] <- 3
dta148$PID5[dta148$qd8a==2] <- 4
dta148$PID5[dta148$PID==3] <- 5

dta148$REGISTERED <- NA
dta148$REGISTERED[dta148$QD9=="Yes"] <- 1
dta148$REGISTERED[dta148$QD9=="No"] <- 2

dta148$BETPER <- NA

dta148$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta148$SUPPORT <- NA
#dta148$SUPPORT[dta148$Q1=="Strongly support"] <- 4
#dta148$SUPPORT[dta148$Q1=="Somewhat support"] <- 3
#dta148$SUPPORT[dta148$Q1=="Somewhat oppose"] <- 2
#dta148$SUPPORT[dta148$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta148$BLACK <- (dta148$race==2)*1
dta148$ASIAN <- (dta148$race==3)*1
dta148$OTHER <- (dta148$race==4)*1

dta148$AGE <- dta148$age
dta148$AGE[dta148$AGE==99] <- NA
dta148$MEDICARE <- (dta148$AGE > 64)*1


dta148$COVERED <- (dta148$qd4==1)*1


dta148$IDEO <- NA
dta148$IDEO[dta148$qd8b==1] <- 3
dta148$IDEO[dta148$qd8b==2] <- 2
dta148$IDEO[dta148$qd8b==3] <- 1

dta148$FAVOR <- NA
dta148$FAVOR[dta148$q2==1] <- 4
dta148$FAVOR[dta148$q2==2] <- 3
dta148$FAVOR[dta148$q2==3] <- 2
dta148$FAVOR[dta148$q2==4] <- 1

# Question Still Not Asked
dta148$SELFEMPLOY <- NA
#dta148$SELFEMPLOY[dta148$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta148$RETIRED <- 0
dta148$RETIRED[dta148$qd3==6] <- 1

dta148$MEDICARESR <- 0
dta148$MEDICARESR <- 1*(dta148$qd4a==4)
dta148$MEDICARESR[dta148$COVERED==0] <- 0

dta148$MEDICAID <- 0
dta148$MEDICAID <- 1*(dta148$qd4a==5)
dta148$MEDICAID[dta148$COVERED==0] <- 0


dta148$HEALTH <- NA
dta148$HEALTH[dta148$qd2==1] <- 5
dta148$HEALTH[dta148$qd2==2] <- 4
dta148$HEALTH[dta148$qd2==3] <- 3
dta148$HEALTH[dta148$qd2==4] <- 2
dta148$HEALTH[dta148$qd2==5] <- 1

dta148$SAWAD <- NA
dta148$SAWADPOS <- NA
dta148$SAWADNEG <- NA
dta148$SAWADBOTH <- NA

dta148$SSTATE <- dta148$state
dta148$STATE <- dta148$state

dta148$MALE <- 1*(dta148$sex==1)

dta148$NUMBER <- 148

dta148$MONTH <- 85

dta148$MARKET <- 0
dta148$MARKET[dta148$q20==2]<-1

dta148$SELFINSURE <- 0
dta148$SELFINSURE[dta148$qd4a==3]<-1
dta148$SELFINSURE[dta148$COVERED==0] <- 0

dta148$EMPLINSURE <- 0
dta148$EMPLINSURE[dta148$qd4a==1]<-1
dta148$EMPLINSURE[dta148$qd4a==2]<-1
dta148$EMPLINSURE[dta148$COVERED==0] <- 0

dta148$PREEXIST <- NA

#sort(table(dta148$Q2CD[dta148$FAVOR==1]))/sum(sort(table(dta148$Q2CD[dta148$FAVOR==1])))

#lout148a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta148)
#summary(#lout148a)
##mf148a <- model.frame(#lout148a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf148a2 <- subsetn(dta148,select=nms)

#lout148b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta148)
#summary(#lout148b)
##mf148b <- model.frame(#lout148b)

#lout148d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta148)
#summary(#lout148d)
##fv148d <- model.frame(#lout148d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv148a2 <- subsetn(dta148,select=fvnms)

dta148$PSRAID <- dta148$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s148 <- subsetn(dta148,select=masterlist, subset=T)



##### January 2016
dta147 <- read.csv.lower("hni147.csv")

dta147$INCOME <- NA
dta147$INCOME[dta147$qd14==1] <- 10
dta147$INCOME[dta147$qd14==2] <- 25
dta147$INCOME[dta147$qd14==3] <- 35
dta147$INCOME[dta147$qd14==4] <- 45
dta147$INCOME[dta147$qd14==5] <- 62.5
dta147$INCOME[dta147$qd14==6] <- 82.5
dta147$INCOME[dta147$qd14==7] <- 95
dta147$INCOME[dta147$qd14==8] <- 200

dta147$HISP2 <- dta147$hisp
dta147$HISP <- (dta147$HISP2==1)*1

dta147$EDUC <- NA
dta147$EDUC[dta147$educ2==1] <- 6
dta147$EDUC[dta147$educ2==2] <- 10
dta147$EDUC[dta147$educ2==3] <- 12
dta147$EDUC[dta147$educ2==4] <- 13
dta147$EDUC[dta147$educ2==5] <- 14
dta147$EDUC[dta147$educ2==6] <- 16
dta147$EDUC[dta147$educ2==7] <- 17
dta147$EDUC[dta147$educ2==8] <- 19

dta147$PID <- NA
dta147$PID[dta147$qd8==2] <- 1
dta147$PID[dta147$qd8>=3 & dta147$qd8<=4] <- 2
dta147$PID[dta147$qd8==1] <- 3

dta147$PID5 <- NA
dta147$PID5[dta147$PID==1] <- 1
dta147$PID5[dta147$qd8a==1] <- 2
dta147$PID5[dta147$qd8a %in%  c(3, 4, 9)] <- 3
dta147$PID5[dta147$qd8a==2] <- 4
dta147$PID5[dta147$PID==3] <- 5

dta147$REGISTERED <- NA
dta147$REGISTERED[dta147$QD9=="Yes"] <- 1
dta147$REGISTERED[dta147$QD9=="No"] <- 2


dta147$BETPER <- NA

dta147$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta147$SUPPORT <- NA
#dta147$SUPPORT[dta147$Q1=="Strongly support"] <- 4
#dta147$SUPPORT[dta147$Q1=="Somewhat support"] <- 3
#dta147$SUPPORT[dta147$Q1=="Somewhat oppose"] <- 2
#dta147$SUPPORT[dta147$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta147$BLACK <- (dta147$race==2)*1
dta147$ASIAN <- (dta147$race==3)*1
dta147$OTHER <- (dta147$race==4)*1

dta147$AGE <- dta147$age
dta147$AGE[dta147$AGE==99] <- NA
dta147$MEDICARE <- (dta147$AGE > 64)*1


dta147$COVERED <- (dta147$qd4==1)*1


dta147$IDEO <- NA
dta147$IDEO[dta147$qd8b==1] <- 3
dta147$IDEO[dta147$qd8b==2] <- 2
dta147$IDEO[dta147$qd8b==3] <- 1

dta147$FAVOR <- NA
dta147$FAVOR[dta147$q1==1] <- 4
dta147$FAVOR[dta147$q1==2] <- 3
dta147$FAVOR[dta147$q1==3] <- 2
dta147$FAVOR[dta147$q1==4] <- 1

# Question Still Not Asked
dta147$SELFEMPLOY <- NA
#dta147$SELFEMPLOY[dta147$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta147$RETIRED <- 0
dta147$RETIRED[dta147$qd3==6] <- 1

dta147$MEDICARESR <- 0
dta147$MEDICARESR <- 1*(dta147$qd4a==4)
dta147$MEDICARESR[dta147$COVERED==0] <- 0

dta147$MEDICAID <- 0
dta147$MEDICAID <- 1*(dta147$qd4a==5)
dta147$MEDICAID[dta147$COVERED==0] <- 0


dta147$HEALTH <- NA
dta147$HEALTH[dta147$qd2==1] <- 5
dta147$HEALTH[dta147$qd2==2] <- 4
dta147$HEALTH[dta147$qd2==3] <- 3
dta147$HEALTH[dta147$qd2==4] <- 2
dta147$HEALTH[dta147$qd2==5] <- 1

dta147$SAWAD <- NA
dta147$SAWADPOS <- NA
dta147$SAWADNEG <- NA
dta147$SAWADBOTH <- NA

dta147$SSTATE <- dta147$state
dta147$STATE <- dta147$state

dta147$MALE <- 1*(dta147$sex==1)

dta147$NUMBER <- 147

dta147$MONTH <- 84

dta147$MARKET <- 0
dta147$MARKET[dta147$q15==2]<-1


dta147$SELFINSURE <- 0
dta147$SELFINSURE[dta147$qd4a==3]<-1
dta147$SELFINSURE[dta147$COVERED==0] <- 0

dta147$EMPLINSURE <- 0
dta147$EMPLINSURE[dta147$qd4a==1]<-1
dta147$EMPLINSURE[dta147$qd4a==2]<-1
dta147$EMPLINSURE[dta147$COVERED==0] <- 0

dta147$PREEXIST <- NA

#sort(table(dta147$Q2CD[dta147$FAVOR==1]))/sum(sort(table(dta147$Q2CD[dta147$FAVOR==1])))

#lout147a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta147)
#summary(#lout147a)
##mf147a <- model.frame(#lout147a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf147a2 <- subsetn(dta147,select=nms)

#lout147b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta147)
#summary(#lout147b)
##mf147b <- model.frame(#lout147b)

#lout147d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta147)
#summary(#lout147d)
##fv147d <- model.frame(#lout147d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv147a2 <- subsetn(dta147,select=fvnms)

dta147$PSRAID <- dta147$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s147 <- subsetn(dta147,select=masterlist, subset=T)


##### December 2015
dta146 <- read.por.upper("hni146.por",to.data.frame=T)

dta146$INCOME <- NA
dta146$INCOME[dta146$QD14=="Less than $20,000"] <- 10
dta146$INCOME[dta146$QD14=="$20,000 to less than $30,000"] <- 25
dta146$INCOME[dta146$QD14=="$30,000 to less than $40,000"] <- 35
dta146$INCOME[dta146$QD14=="$40,000 to less than $50,000"] <- 45
dta146$INCOME[dta146$QD14=="$50,000 to less than $75,000"] <- 62.5
dta146$INCOME[dta146$QD14=="$75,000 to less than $90,000"] <- 82.5
dta146$INCOME[dta146$QD14=="$90,000 to less than $100,000"] <- 95
dta146$INCOME[dta146$QD14=="$100,000 or more"] <- 200

dta146$HISP2 <- dta146$HISP
dta146$HISP <- (dta146$HISP2=="Yes")*1

dta146$EDUC <- NA
dta146$EDUC[dta146$EDUC2=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta146$EDUC[dta146$EDUC2=="High school incomplete (Grades 9-11 or Grade 12 with no diploma)"] <- 10
dta146$EDUC[dta146$EDUC2=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta146$EDUC[dta146$EDUC2=="Some college, no degree (includes some community college)"] <- 13
dta146$EDUC[dta146$EDUC2=="Two year associate degree from a college or university"] <- 14
dta146$EDUC[dta146$EDUC2=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta146$EDUC[dta146$EDUC2=="Some postgraduate or professional school, no postgraduate degree"] <- 17
dta146$EDUC[dta146$EDUC2=="Post-graduate or professional degree, including master's, doctorate, medical, or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta146$PID <- NA
dta146$PID[dta146$QD8=="Democrat"] <- 1
dta146$PID[dta146$QD8 %in% c("Independent","Or what (includes Other and None)")] <- 2
dta146$PID[dta146$QD8=="Republican"] <- 3

dta146$PID5 <- NA
dta146$PID5[dta146$PID==1] <- 1
dta146$PID5[dta146$QD8A=="Democratic"] <- 2
dta146$PID5[dta146$QD8A %in% c("(DO NOT READ) Independent/don't lean to either party", "(DO NOT READ) Other party", "(DO NOT READ) Don't know/Refused")] <- 3
dta146$PID5[dta146$QD8A=="Republican"] <- 4
dta146$PID5[dta146$PID==3] <- 5

dta146$REGISTERED <- NA
dta146$REGISTERED[dta146$QD9=="Yes"] <- 1
dta146$REGISTERED[dta146$QD9=="No"] <- 2


dta146$BETPER <- NA
dta146$BETPER[dta146$Q4=="Helped"] <- 3
dta146$BETPER[dta146$Q4=="(DO NOT READ) Don't know/Refused"] <- 2
dta146$BETPER[dta146$Q4=="(DO NOT READ) Both helped and hurt"] <- 2
dta146$BETPER[dta146$Q4=="No direct impact"] <- 2
dta146$BETPER[dta146$Q4=="Hurt"] <- 1

dta146$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta146$SUPPORT <- NA
#dta146$SUPPORT[dta146$Q1=="Strongly support"] <- 4
#dta146$SUPPORT[dta146$Q1=="Somewhat support"] <- 3
#dta146$SUPPORT[dta146$Q1=="Somewhat oppose"] <- 2
#dta146$SUPPORT[dta146$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta146$BLACK <- (dta146$RACE=="Black or African-American")*1
dta146$ASIAN <- (dta146$RACE=="Asian")*1
dta146$OTHER <- (dta146$RACE=="Other or mixed race (SPECIFY)")*1

dta146$AGE <- dta146$AGE
dta146$AGE[dta146$AGE==99] <- NA
dta146$MEDICARE <- (as.numeric(as.character(dta146$AGE)) > 64)*1


dta146$COVERED <- (dta146$QD4=="Covered by health insurance")*1


dta146$IDEO <- NA
dta146$IDEO[dta146$QD8B=="Liberal"] <- 3
dta146$IDEO[dta146$QD8B=="Moderate"] <- 2
dta146$IDEO[dta146$QD8B=="Conservative"] <- 1

dta146$FAVOR <- NA
dta146$FAVOR[dta146$Q1=="Very favorable"] <- 4
dta146$FAVOR[dta146$Q1=="Somewhat favorable"] <- 3
dta146$FAVOR[dta146$Q1=="Somewhat unfavorable"] <- 2
dta146$FAVOR[dta146$Q1=="Very unfavorable"] <- 1

# Question Still Not Asked
dta146$SELFEMPLOY <- NA
#dta146$SELFEMPLOY[dta146$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta146$RETIRED <- 0
dta146$RETIRED[dta146$QD3=="Retired"] <- 1

dta146$MEDICARESR <- 0
dta146$MEDICARESR <- 1*(dta146$QD4A=="Medicare")
dta146$MEDICARESR[dta146$QD4A %in% c(NA)] <- 0

dta146$MEDICAID <- 0
dta146$MEDICAID <- 1*(dta146$QD4A=="Medicaid/[STATE-SPECIFIC MEDICAID NAME]")
dta146$MEDICAID[dta146$QD4A %in% c(NA)] <- 0


dta146$HEALTH <- NA
dta146$HEALTH[dta146$QD2=="Excellent"] <- 5
dta146$HEALTH[dta146$QD2=="Very good"] <- 4
dta146$HEALTH[dta146$QD2=="Good"] <- 3
dta146$HEALTH[dta146$QD2=="Only fair"] <- 2
dta146$HEALTH[dta146$QD2=="Poor"] <- 1

dta146$SAWAD <- NA
dta146$SAWADPOS <- NA
dta146$SAWADNEG <- NA
dta146$SAWADBOTH <- NA

dta146$SSTATE <- dta146$STATE

dta146$MALE <- 1*(dta146$SEX=="Male")

dta146$NUMBER <- 146

dta146$MONTH <- 83

dta146$MARKET <- 0
dta146$MARKET[dta146$Q29=="From healthcare.gov or [STATE MARKETPLACE NAME]"]<-1

dta146$SELFINSURE <- 0
dta146$SELFINSURE[dta146$QD4A=="Plan you purchased yourself"]<-1

dta146$EMPLINSURE <- 0
dta146$EMPLINSURE[dta146$QD4A=="Plan through your employer"]<-1
dta146$EMPLINSURE[dta146$QD4A=="Plan through your spouse's employer"]<-1

dta146$PREEXIST <- NA

#sort(table(dta146$Q2CD[dta146$FAVOR==1]))/sum(sort(table(dta146$Q2CD[dta146$FAVOR==1])))

###lout146a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta146)
##summary(#lout146a)
###mf146a <- model.frame(#lout146a)

#### full data
#nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
##mf146a2 <- subsetn(dta146,select=nms)

###lout146b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta146)
##summary(#lout146b)
###mf146b <- model.frame(#lout146b)

#lout146d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta146)
#summary(#lout146d)
##fv146d <- model.frame(#lout146d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv146a2 <- subsetn(dta146,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s146 <- subsetn(dta146,select=masterlist, subset=T)


setwd("/Users/Sam/Dropbox/sammitchell/ACA/csvfiles")
##### November 2015
dta145 <- read.csv.lower("hni145.csv")

dta145$INCOME <- NA
dta145$INCOME[dta145$qd14=="Less than $20,000"] <- 10
dta145$INCOME[dta145$qd14=="$20,000 to less than $30,000"] <- 25
dta145$INCOME[dta145$qd14=="$30,000 to less than $40,000"] <- 35
dta145$INCOME[dta145$qd14=="$40,000 to less than $50,000"] <- 45
dta145$INCOME[dta145$qd14=="$50,000 to less than $75,000"] <- 62.5
dta145$INCOME[dta145$qd14=="$75,000 to less than $90,000"] <- 82.5
dta145$INCOME[dta145$qd14=="$90,000 to less than $100,000"] <- 95
dta145$INCOME[dta145$qd14=="$100,000 or more"] <- 200

dta145$HISP <- (dta145$hisp=="Yes")*1

dta145$EDUC <- NA
dta145$EDUC[dta145$educ2=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta145$EDUC[dta145$educ2=="High school incomplete (Grades 9-11 or Grade 12 with no diploma)"] <- 10
dta145$EDUC[dta145$educ2=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta145$EDUC[dta145$educ2=="Some college, no degree (includes some community college)"] <- 13
dta145$EDUC[dta145$educ2=="Two year associate degree from a college or university"] <- 14
dta145$EDUC[dta145$educ2=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta145$EDUC[dta145$educ2=="Some postgraduate or professional school, no postgraduate degree"] <- 17
dta145$EDUC[dta145$educ2=="Post-graduate or professional degree, including master's, doctorate, medical, or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta145$PID <- NA
dta145$PID[dta145$qd8=="Democrat"] <- 1
dta145$PID[dta145$qd8 %in% c("Independent","Or what (includes Other and None)")] <- 2
dta145$PID[dta145$qd8=="Republican"] <- 3

dta145$PID5 <- NA
dta145$PID5[dta145$PID==1] <- 1
dta145$PID5[dta145$qd8a=="Democratic"] <- 2
dta145$PID5[dta145$qd8a %in% c("(DO NOT READ) Independent/don't lean to either party", "(DO NOT READ) Other party", "(DO NOT READ) Don't know/Refused")] <- 3
dta145$PID5[dta145$qd8a=="Republican"] <- 4
dta145$PID5[dta145$PID==3] <- 5

dta145$REGISTERED <- NA
dta145$REGISTERED[dta145$qd9=="Yes"] <- 1
dta145$REGISTERED[dta145$qd9=="No"] <- 2


dta145$BETPER <- NA

dta145$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta145$SUPPORT <- NA
#dta145$SUPPORT[dta145$Q1=="Strongly support"] <- 4
#dta145$SUPPORT[dta145$Q1=="Somewhat support"] <- 3
#dta145$SUPPORT[dta145$Q1=="Somewhat oppose"] <- 2
#dta145$SUPPORT[dta145$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta145$BLACK <- (dta145$race=="Black or African-American")*1
dta145$ASIAN <- (dta145$race=="Asian")*1
dta145$OTHER <- (dta145$race=="Other or mixed race (SPECIFY)")*1

dta145$AGE <- dta145$age
dta145$AGE[dta145$age==99] <- NA
dta145$AGE[dta145$AGE=="(DO NOT READ) Don't know/Refused"] <- NA
dta145$MEDICARE <- (as.numeric(as.character(dta145$AGE)) > 64)*1


dta145$COVERED <- (dta145$qd4=="Covered by health insurance")*1


dta145$IDEO <- NA
dta145$IDEO[dta145$qd8b=="Liberal"] <- 3
dta145$IDEO[dta145$qd8b=="Moderate"] <- 2
dta145$IDEO[dta145$qd8b=="Conservative"] <- 1

dta145$FAVOR <- NA
dta145$FAVOR[dta145$q1=="Very favorable"] <- 4
dta145$FAVOR[dta145$q1=="Somewhat favorable"] <- 3
dta145$FAVOR[dta145$q1=="Somewhat unfavorable"] <- 2
dta145$FAVOR[dta145$q1=="Very unfavorable"] <- 1

# Question Still Not Asked
dta145$SELFEMPLOY <- NA
#dta145$SELFEMPLOY[dta145$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta145$RETIRED <- 0
dta145$RETIRED[dta145$qd3=="Retired"] <- 1

dta145$MEDICARESR <- 0
dta145$MEDICARESR <- 1*(dta145$qd4a=="Medicare")
dta145$MEDICARESR[dta145$qd4a %in% c(NA)] <- 0

dta145$MEDICAID <- 0
dta145$MEDICAID <- 1*(dta145$qd4a=="Medicaid/[STATE-SPECIFIC MEDICAID NAME]")
dta145$MEDICAID[dta145$qd4a %in% c(NA)] <- 0


dta145$HEALTH <- NA
dta145$HEALTH[dta145$qd2=="Excellent"] <- 5
dta145$HEALTH[dta145$qd2=="Very good"] <- 4
dta145$HEALTH[dta145$qd2=="Good"] <- 3
dta145$HEALTH[dta145$qd2=="Only fair"] <- 2
dta145$HEALTH[dta145$qd2=="Poor"] <- 1

dta145$SAWAD <- NA
dta145$SAWADPOS <- NA
dta145$SAWADNEG <- NA
dta145$SAWADBOTH <- NA

dta145$SSTATE <- dta145$state
dta145$STATE <- dta145$state

dta145$MALE <- 1*(dta145$sex=="Male")

dta145$NUMBER <- 145

dta145$MONTH <- 82

dta145$MARKET <- 0
dta145$MARKET[dta145$q17=="From healthcare.gov or [STATE MARKETPLACE NAME]"]<-1

dta145$SELFINSURE <- 0
dta145$SELFINSURE[dta145$qd4a=="Plan you purchased yourself"]<-1

dta145$EMPLINSURE <- 0
dta145$EMPLINSURE[dta145$qd4a=="Plan through your employer"]<-1
dta145$EMPLINSURE[dta145$qd4a=="Plan through your spouse's employer"]<-1

dta145$PREEXIST <- NA

#sort(table(dta145$Q2CD[dta145$FAVOR==1]))/sum(sort(table(dta145$Q2CD[dta145$FAVOR==1])))

###lout145a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta145)
##summary(#lout145a)
###mf145a <- model.frame(#lout145a)

#### full data
#nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
##mf145a2 <- subsetn(dta145,select=nms)

###lout145b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta145)
##summary(#lout145b)
###mf145b <- model.frame(#lout145b)

#lout145d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta145)
#summary(#lout145d)
##fv145d <- model.frame(#lout145d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv145a2 <- subsetn(dta145,select=fvnms)

dta145$PSRAID <- dta145$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s145 <- subsetn(dta145,select=masterlist, subset=T)



##### October 2015
dta144 <- read.por.upper("hni144.por",to.data.frame=T)

dta144$INCOME <- NA
dta144$INCOME[dta144$QD14=="Less than $20,000"] <- 10
dta144$INCOME[dta144$QD14=="$20,000 to less than $30,000"] <- 25
dta144$INCOME[dta144$QD14=="$30,000 to less than $40,000"] <- 35
dta144$INCOME[dta144$QD14=="$40,000 to less than $50,000"] <- 45
dta144$INCOME[dta144$QD14=="$50,000 to less than $75,000"] <- 62.5
dta144$INCOME[dta144$QD14=="$75,000 to less than $90,000"] <- 82.5
dta144$INCOME[dta144$QD14=="$90,000 to less than $100,000"] <- 95
dta144$INCOME[dta144$QD14=="$100,000 or more"] <- 200

dta144$HISP2 <- dta144$HISP
dta144$HISP <- (dta144$HISP2=="Yes")*1

dta144$EDUC <- NA
dta144$EDUC[dta144$EDUC2=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta144$EDUC[dta144$EDUC2=="High school incomplete (Grades 9-11 or Grade 12 with no diploma)"] <- 10
dta144$EDUC[dta144$EDUC2=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta144$EDUC[dta144$EDUC2=="Some college, no degree (includes some community college)"] <- 13
dta144$EDUC[dta144$EDUC2=="Two year associate degree from a college or university"] <- 14
dta144$EDUC[dta144$EDUC2=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta144$EDUC[dta144$EDUC2=="Some postgraduate or professional school, no postgraduate degree"] <- 17
dta144$EDUC[dta144$EDUC2=="Post-graduate or professional degree, including master's, doctorate, medical, or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta144$PID <- NA
dta144$PID[dta144$QD8=="Democrat"] <- 1
dta144$PID[dta144$QD8 %in% c("Independent","Or what (includes Other and None)")] <- 2
dta144$PID[dta144$QD8=="Republican"] <- 3

dta144$PID5 <- NA
dta144$PID5[dta144$PID==1] <- 1
dta144$PID5[dta144$QD8A=="Democratic"] <- 2
dta144$PID5[dta144$QD8A %in% c("(DO NOT READ) Independent/don't lean to either party", "(DO NOT READ) Other party", "(DO NOT READ) Don't know/Refused")] <- 3
dta144$PID5[dta144$QD8A=="Republican"] <- 4
dta144$PID5[dta144$PID==3] <- 5

dta144$REGISTERED <- NA
dta144$REGISTERED[dta144$QD9=="Yes"] <- 1
dta144$REGISTERED[dta144$QD9=="No"] <- 2


dta144$BETPER <- NA

dta144$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta144$SUPPORT <- NA
#dta144$SUPPORT[dta144$Q1=="Strongly support"] <- 4
#dta144$SUPPORT[dta144$Q1=="Somewhat support"] <- 3
#dta144$SUPPORT[dta144$Q1=="Somewhat oppose"] <- 2
#dta144$SUPPORT[dta144$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta144$BLACK <- (dta144$RACE=="Black or African-American")*1
dta144$ASIAN <- (dta144$RACE=="Asian")*1
dta144$OTHER <- (dta144$RACE=="Other or mixed race (SPECIFY)")*1

dta144$AGE <- dta144$AGE
dta144$AGE[dta144$AGE==99] <- NA
dta144$MEDICARE <- (as.numeric(as.character(dta144$AGE)) > 64)*1


dta144$COVERED <- (dta144$QD4=="Covered by health insurance")*1


dta144$IDEO <- NA
dta144$IDEO[dta144$QD8B=="Liberal"] <- 3
dta144$IDEO[dta144$QD8B=="Moderate"] <- 2
dta144$IDEO[dta144$QD8B=="Conservative"] <- 1

dta144$FAVOR <- NA
dta144$FAVOR[dta144$Q1=="Very favorable"] <- 4
dta144$FAVOR[dta144$Q1=="Somewhat favorable"] <- 3
dta144$FAVOR[dta144$Q1=="Somewhat unfavorable"] <- 2
dta144$FAVOR[dta144$Q1=="Very unfavorable"] <- 1

# Question Still Not Asked
dta144$SELFEMPLOY <- NA
#dta144$SELFEMPLOY[dta144$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta144$RETIRED <- 0
dta144$RETIRED[dta144$QD3=="Retired"] <- 1

dta144$MEDICARESR <- 0
dta144$MEDICARESR <- 1*(dta144$QD4A=="Medicare")
dta144$MEDICARESR[dta144$QD4A %in% c(NA)] <- 0

dta144$MEDICAID <- 0
dta144$MEDICAID <- 1*(dta144$QD4A=="Medicaid/[STATE-SPECIFIC MEDICAID NAME]")
dta144$MEDICAID[dta144$QD4A %in% c(NA)] <- 0


dta144$HEALTH <- NA
dta144$HEALTH[dta144$QD2=="Excellent"] <- 5
dta144$HEALTH[dta144$QD2=="Very good "] <- 4
dta144$HEALTH[dta144$QD2=="Good"] <- 3
dta144$HEALTH[dta144$QD2=="Only fair"] <- 2
dta144$HEALTH[dta144$QD2=="Poor"] <- 1

dta144$SAWAD <- NA
dta144$SAWADPOS <- NA
dta144$SAWADNEG <- NA
dta144$SAWADBOTH <- NA

dta144$SSTATE <- dta144$STATE

dta144$MALE <- 1*(dta144$SEX=="Male")

dta144$NUMBER <- 144

dta144$MONTH <- 81

dta144$MARKET <- 0
dta144$MARKET[dta144$Q24=="From healthcare.gov or [STATE MARKETPLACE NAME]"]<-1

dta144$SELFINSURE <- 0
dta144$SELFINSURE[dta144$QD4A=="Plan you purchased yourself"]<-1

dta144$EMPLINSURE <- 0
dta144$EMPLINSURE[dta144$QD4A=="Plan through your employer"]<-1
dta144$EMPLINSURE[dta144$QD4A=="Plan through your spouse's employer"]<-1

dta144$PREEXIST <- NA

#sort(table(dta144$Q2CD[dta144$FAVOR==1]))/sum(sort(table(dta144$Q2CD[dta144$FAVOR==1])))

###lout144a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta144)
##summary(#lout144a)
###mf144a <- model.frame(#lout144a)

#### full data
#nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
##mf144a2 <- subsetn(dta144,select=nms)

###lout144b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta144)
##summary(#lout144b)
###mf144b <- model.frame(#lout144b)

#lout144d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta144)
#summary(#lout144d)
##fv144d <- model.frame(#lout144d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv144a2 <- subsetn(dta144,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s144 <- subsetn(dta144,select=masterlist, subset=T)

##### September 2015
dta143 <- read.por.upper("hni143.por",to.data.frame=T)

dta143$INCOME <- NA
dta143$INCOME[dta143$QD14=="Less than $20,000"] <- 10
dta143$INCOME[dta143$QD14=="$20,000 to less than $30,000"] <- 25
dta143$INCOME[dta143$QD14=="$30,000 to less than $40,000"] <- 35
dta143$INCOME[dta143$QD14=="$40,000 to less than $50,000"] <- 45
dta143$INCOME[dta143$QD14=="$50,000 to less than $75,000"] <- 62.5
dta143$INCOME[dta143$QD14=="$75,000 to less than $90,000"] <- 82.5
dta143$INCOME[dta143$QD14=="$90,000 to less than $100,000"] <- 95
dta143$INCOME[dta143$QD14=="$100,000 or more"] <- 200

dta143$HISP2 <- dta143$HISP
dta143$HISP <- (dta143$HISP2=="Yes")*1

dta143$EDUC <- NA
dta143$EDUC[dta143$EDUC2=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta143$EDUC[dta143$EDUC2=="High school incomplete (Grades 9-11 or Grade 12 with no diploma)"] <- 10
dta143$EDUC[dta143$EDUC2=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta143$EDUC[dta143$EDUC2=="Some college, no degree (includes some community college)"] <- 13
dta143$EDUC[dta143$EDUC2=="Two year associate degree from a college or university"] <- 14
dta143$EDUC[dta143$EDUC2=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta143$EDUC[dta143$EDUC2=="Some postgraduate or professional schooling, no postgraduate degree"] <- 17
dta143$EDUC[dta143$EDUC2=="Post-graduate or professional degree, including master's, doctorate, medical, or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta143$PID <- NA
dta143$PID[dta143$QD8=="Democrat"] <- 1
dta143$PID[dta143$QD8 %in% c("Independent","Or what (includes Other and None)")] <- 2
dta143$PID[dta143$QD8=="Republican"] <- 3

dta143$PID5 <- NA
dta143$PID5[dta143$PID==1] <- 1
dta143$PID5[dta143$QD8A=="Democratic"] <- 2
dta143$PID5[dta143$QD8A %in% c("(DO NOT READ) Independent/don't lean to either party", "(DO NOT READ) Other party", "(DO NOT READ) Don't know/Refused")] <- 3
dta143$PID5[dta143$QD8A=="Republican"] <- 4
dta143$PID5[dta143$PID==3] <- 5

dta143$REGISTERED <- NA
dta143$REGISTERED[dta143$QD9=="Yes"] <- 1
dta143$REGISTERED[dta143$QD9=="No"] <- 2


dta143$BETPER <- NA

dta143$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta143$SUPPORT <- NA
#dta143$SUPPORT[dta143$Q1=="Strongly support"] <- 4
#dta143$SUPPORT[dta143$Q1=="Somewhat support"] <- 3
#dta143$SUPPORT[dta143$Q1=="Somewhat oppose"] <- 2
#dta143$SUPPORT[dta143$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta143$BLACK <- (dta143$RACE=="Black or African-American")*1
dta143$ASIAN <- (dta143$RACE=="Asian")*1
dta143$OTHER <- (dta143$RACE=="Other or mixed race (SPECIFY)")*1

dta143$AGE <- dta143$AGE
dta143$AGE[dta143$AGE==99] <- NA
dta143$MEDICARE <- (dta143$AGE > 64)*1


dta143$COVERED <- (dta143$QD4=="Covered by health insurance")*1


dta143$IDEO <- NA
dta143$IDEO[dta143$QD8B=="Liberal"] <- 3
dta143$IDEO[dta143$QD8B=="Moderate"] <- 2
dta143$IDEO[dta143$QD8B=="Conservative"] <- 1

dta143$FAVOR <- NA
dta143$FAVOR[dta143$Q1=="Very favorable"] <- 4
dta143$FAVOR[dta143$Q1=="Somewhat favorable"] <- 3
dta143$FAVOR[dta143$Q1=="Somewhat unfavorable"] <- 2
dta143$FAVOR[dta143$Q1=="Very unfavorable"] <- 1

# Question Still Not Asked
dta143$SELFEMPLOY <- NA
#dta143$SELFEMPLOY[dta143$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta143$RETIRED <- 0
dta143$RETIRED[dta143$QD3=="Retired"] <- 1

dta143$MEDICARESR <- 0
dta143$MEDICARESR <- 1*(dta143$QD4A=="Medicare")
dta143$MEDICARESR[dta143$QD4A %in% c(NA)] <- 0

dta143$MEDICAID <- 0
dta143$MEDICAID <- 1*(dta143$QD4A=="Medicaid/[STATE-SPECIFIC MEDICAID NAME]")
dta143$MEDICAID[dta143$QD4A %in% c(NA)] <- 0


dta143$HEALTH <- NA
dta143$HEALTH[dta143$QD2=="Excellent"] <- 5
dta143$HEALTH[dta143$QD2=="Very good "] <- 4
dta143$HEALTH[dta143$QD2=="Good"] <- 3
dta143$HEALTH[dta143$QD2=="Only fair"] <- 2
dta143$HEALTH[dta143$QD2=="Poor"] <- 1

dta143$SAWAD <- NA
dta143$SAWADPOS <- NA
dta143$SAWADNEG <- NA
dta143$SAWADBOTH <- NA

dta143$SSTATE <- dta143$STATE

dta143$MALE <- 1*(dta143$SEX=="Male")

dta143$NUMBER <- 143

dta143$MONTH <- 80

dta143$MARKET <- 0
dta143$MARKET[dta143$Q23=="From healthcare.gov or [STATE MARKETPLACE NAME]"]<-1

dta143$SELFINSURE <- 0
dta143$SELFINSURE[dta143$QD4A=="Plan you purchased yourself"]<-1

dta143$EMPLINSURE <- 0
dta143$EMPLINSURE[dta143$QD4A=="Plan through your employer"]<-1
dta143$EMPLINSURE[dta143$QD4A=="Plan through your spouse's employer"]<-1

dta143$PREEXIST <- NA

#sort(table(dta143$Q2CD[dta143$FAVOR==1]))/sum(sort(table(dta143$Q2CD[dta143$FAVOR==1])))

###lout143a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta143)
##summary(#lout143a)
###mf143a <- model.frame(#lout143a)

#### full data
#nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
##mf143a2 <- subsetn(dta143,select=nms)

###lout143b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta143)
##summary(#lout143b)
###mf143b <- model.frame(#lout143b)

#lout143d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta143)
#summary(#lout143d)
##fv143d <- model.frame(#lout143d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv143a2 <- subsetn(dta143,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s143 <- subsetn(dta143,select=masterlist, subset=T)


##### August 2015
dta142 <- read.por.upper("hni142.por",to.data.frame=T)

dta142$INCOME <- NA
dta142$INCOME[dta142$QD14=="Less than $20,000"] <- 10
dta142$INCOME[dta142$QD14=="$20,000 to less than $30,000"] <- 25
dta142$INCOME[dta142$QD14=="$30,000 to less than $40,000"] <- 35
dta142$INCOME[dta142$QD14=="$40,000 to less than $50,000"] <- 45
dta142$INCOME[dta142$QD14=="$50,000 to less than $75,000"] <- 62.5
dta142$INCOME[dta142$QD14=="$75,000 to less than $90,000"] <- 82.5
dta142$INCOME[dta142$QD14=="$90,000 to less than $100,000"] <- 95
dta142$INCOME[dta142$QD14=="$100,000 or more"] <- 200

dta142$HISP2 <- dta142$HISP
dta142$HISP <- (dta142$HISP2=="Yes")*1

dta142$EDUC <- NA
dta142$EDUC[dta142$EDUC2=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta142$EDUC[dta142$EDUC2=="High school incomplete (Grades 9-11 or Grade 12 with no diploma)"] <- 10
dta142$EDUC[dta142$EDUC2=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta142$EDUC[dta142$EDUC2=="Some college, no degree (includes some community college)"] <- 13
dta142$EDUC[dta142$EDUC2=="Two year associate degree from a college or university"] <- 14
dta142$EDUC[dta142$EDUC2=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta142$EDUC[dta142$EDUC2=="Some postgraduate or professional schooling, no postgraduate degree"] <- 17
dta142$EDUC[dta142$EDUC2=="Post-graduate or professional degree, including master's, doctorate, medical, or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta142$PID <- NA
dta142$PID[dta142$QD8=="Democrat"] <- 1
dta142$PID[dta142$QD8 %in% c("Independent","Or what (includes Other and None)")] <- 2
dta142$PID[dta142$QD8=="Republican"] <- 3

dta142$PID5 <- NA
dta142$PID5[dta142$PID==1] <- 1
dta142$PID5[dta142$QD8A=="Democratic"] <- 2
dta142$PID5[dta142$QD8A %in% c("(DO NOT READ) Independent/don't lean to either party", "(DO NOT READ) Other party", "(DO NOT READ) Don't know/Refused")] <- 3
dta142$PID5[dta142$QD8A=="Republican"] <- 4
dta142$PID5[dta142$PID==3] <- 5

dta142$REGISTERED <- NA
dta142$REGISTERED[dta142$QD9=="Yes"] <- 1
dta142$REGISTERED[dta142$QD9=="No"] <- 2


dta142$BETPER <- NA

dta142$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta142$SUPPORT <- NA
#dta142$SUPPORT[dta142$Q1=="Strongly support"] <- 4
#dta142$SUPPORT[dta142$Q1=="Somewhat support"] <- 3
#dta142$SUPPORT[dta142$Q1=="Somewhat oppose"] <- 2
#dta142$SUPPORT[dta142$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta142$BLACK <- (dta142$RACE=="Black or African-American")*1
dta142$ASIAN <- (dta142$RACE=="Asian")*1
dta142$OTHER <- (dta142$RACE=="Other or mixed race (SPECIFY)")*1

dta142$AGE <- dta142$AGE
dta142$AGE[dta142$AGE==99] <- NA
dta142$MEDICARE <- (dta142$AGE > 64)*1


dta142$COVERED <- (dta142$QD4=="Covered by health insurance")*1


dta142$IDEO <- NA
dta142$IDEO[dta142$QD8B=="Liberal"] <- 3
dta142$IDEO[dta142$QD8B=="Moderate"] <- 2
dta142$IDEO[dta142$QD8B=="Conservative"] <- 1

dta142$FAVOR <- NA
dta142$FAVOR[dta142$Q1=="Very favorable"] <- 4
dta142$FAVOR[dta142$Q1=="Somewhat favorable"] <- 3
dta142$FAVOR[dta142$Q1=="Somewhat unfavorable"] <- 2
dta142$FAVOR[dta142$Q1=="Very unfavorable"] <- 1

# Question Still Not Asked
dta142$SELFEMPLOY <- NA
#dta142$SELFEMPLOY[dta142$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta142$RETIRED <- 0
dta142$RETIRED[dta142$QD3=="Retired"] <- 1

dta142$MEDICARESR <- 0
dta142$MEDICARESR <- 1*(dta142$QD4A=="Medicare")
dta142$MEDICARESR[dta142$QD4A %in% c(NA)] <- 0

dta142$MEDICAID <- 0
dta142$MEDICAID <- 1*(dta142$QD4A=="Medicaid/[STATE-SPECIFIC MEDICAID NAME]")
dta142$MEDICAID[dta142$QD4A %in% c(NA)] <- 0


dta142$HEALTH <- NA
dta142$HEALTH[dta142$QD2=="Excellent"] <- 5
dta142$HEALTH[dta142$QD2=="Very good "] <- 4
dta142$HEALTH[dta142$QD2=="Good"] <- 3
dta142$HEALTH[dta142$QD2=="Only fair"] <- 2
dta142$HEALTH[dta142$QD2=="Poor"] <- 1

dta142$SAWAD <- NA
dta142$SAWADPOS <- NA
dta142$SAWADNEG <- NA
dta142$SAWADBOTH <- NA

dta142$SSTATE <- dta142$STATE

dta142$MALE <- 1*(dta142$SEX=="Male")

dta142$NUMBER <- 142

dta142$MONTH <- 79

dta142$MARKET <- 0
dta142$MARKET[dta142$Q25=="From healthcare.gov or [STATE MARKETPLACE NAME]"]<-1

dta142$SELFINSURE <- 0
dta142$SELFINSURE[dta142$QD4A=="Plan you purchased yourself"]<-1

dta142$EMPLINSURE <- 0
dta142$EMPLINSURE[dta142$QD4A=="Plan through your employer"]<-1
dta142$EMPLINSURE[dta142$QD4A=="Plan through your spouse's employer"]<-1

dta142$PREEXIST <- NA

#sort(table(dta142$Q2CD[dta142$FAVOR==1]))/sum(sort(table(dta142$Q2CD[dta142$FAVOR==1])))

###lout142a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta142)
##summary(#lout142a)
###mf142a <- model.frame(#lout142a)

#### full data
#nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
##mf142a2 <- subsetn(dta142,select=nms)

###lout142b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta142)
##summary(#lout142b)
###mf142b <- model.frame(#lout142b)

#lout142d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta142)
#summary(#lout142d)
##fv142d <- model.frame(#lout142d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv142a2 <- subsetn(dta142,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s142 <- subsetn(dta142,select=masterlist, subset=T)

##### July 2015
dta141 <- read.por.upper("hni141.por",to.data.frame=T)


dta141$INCOME <- NA
dta141$INCOME[dta141$QD14=="Less than $20,000"] <- 10
dta141$INCOME[dta141$QD14=="$20,000 to less than $30,000"] <- 25
dta141$INCOME[dta141$QD14=="$30,000 to less than $40,000"] <- 35
dta141$INCOME[dta141$QD14=="$40,000 to less than $50,000"] <- 45
dta141$INCOME[dta141$QD14=="$50,000 to less than $75,000"] <- 62.5
dta141$INCOME[dta141$QD14=="$75,000 to less than $90,000"] <- 82.5
dta141$INCOME[dta141$QD14=="$90,000 to less than $100,000"] <- 95
dta141$INCOME[dta141$QD14=="$100,000 or more"] <- 200

dta141$HISP2 <- dta141$HISP
dta141$HISP <- (dta141$HISP2=="Yes")*1

dta141$EDUC <- NA
dta141$EDUC[dta141$EDUC2=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta141$EDUC[dta141$EDUC2=="High school incomplete (Grades 9-11 or Grade 12 with no diploma)"] <- 10
dta141$EDUC[dta141$EDUC2=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta141$EDUC[dta141$EDUC2=="Some college, no degree (includes some community college)"] <- 13
dta141$EDUC[dta141$EDUC2=="Two year associate degree from a college or university"] <- 14
dta141$EDUC[dta141$EDUC2=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta141$EDUC[dta141$EDUC2=="Some postgraduate or professional school, no postgraduate degree"] <- 17
dta141$EDUC[dta141$EDUC2=="Post-graduate or professional degree, including master's, doctorate, medical, or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta141$PID <- NA
dta141$PID[dta141$QD8=="Democrat"] <- 1
dta141$PID[dta141$QD8 %in% c("Independent","Or what (includes Other and None)")] <- 2
dta141$PID[dta141$QD8=="Republican"] <- 3

dta141$PID5 <- NA
dta141$PID5[dta141$PID==1] <- 1
dta141$PID5[dta141$QD8A=="Democratic"] <- 2
dta141$PID5[dta141$QD8A %in% c("(DO NOT READ) Independent/don't lean to either party", "(DO NOT READ) Other party", "(DO NOT READ) Don't know/Refused")] <- 3
dta141$PID5[dta141$QD8A=="Republican"] <- 4
dta141$PID5[dta141$PID==3] <- 5


dta141$BETPER <- NA
dta141$BETPER[dta141$Q4=="Helped"] <- 3
dta141$BETPER[dta141$Q4=="(DO NOT READ) Don't know/Refused"] <- 2
dta141$BETPER[dta141$Q4=="(DO NOT READ) Both helped and hurt"] <- 2
dta141$BETPER[dta141$Q4=="No direct impact"] <- 2
dta141$BETPER[dta141$Q4=="Hurt"] <- 1

dta141$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta141$SUPPORT <- NA
#dta141$SUPPORT[dta141$Q1=="Strongly support"] <- 4
#dta141$SUPPORT[dta141$Q1=="Somewhat support"] <- 3
#dta141$SUPPORT[dta141$Q1=="Somewhat oppose"] <- 2
#dta141$SUPPORT[dta141$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta141$BLACK <- (dta141$RACE=="Black or African-American")*1
dta141$ASIAN <- (dta141$RACE=="Asian")*1
dta141$OTHER <- (dta141$RACE=="Other or mixed race (SPECIFY)")*1

dta141$AGE <- dta141$AGE
dta141$AGE[dta141$AGE==99] <- NA
dta141$MEDICARE <- (dta141$AGE > 64)*1


dta141$COVERED <- (dta141$QD4=="Covered by health insurance")*1


dta141$IDEO <- NA
dta141$IDEO[dta141$QD8B=="Liberal"] <- 3
dta141$IDEO[dta141$QD8B=="Moderate"] <- 2
dta141$IDEO[dta141$QD8B=="Conservative"] <- 1

dta141$FAVOR <- NA
dta141$FAVOR[dta141$Q1=="Very favorable"] <- 4
dta141$FAVOR[dta141$Q1=="Somewhat favorable"] <- 3
dta141$FAVOR[dta141$Q1=="Somewhat unfavorable"] <- 2
dta141$FAVOR[dta141$Q1=="Very unfavorable"] <- 1

# Question Still Not Asked
dta141$SELFEMPLOY <- NA
#dta141$SELFEMPLOY[dta141$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta141$RETIRED <- 0
dta141$RETIRED[dta141$QD3=="Retired"] <- 1

dta141$MEDICARESR <- 0
dta141$MEDICARESR <- 1*(dta141$QD4A=="Medicare")
dta141$MEDICARESR[dta141$QD4A %in% c(NA)] <- 0

dta141$MEDICAID <- 0
dta141$MEDICAID <- 1*(dta141$QD4A=="Medicaid/[STATE-SPECIFIC MEDICAID NAME]")
dta141$MEDICAID[dta141$QD4A %in% c(NA)] <- 0


dta141$HEALTH <- NA
#dta141$HEALTH[dta141$QD2=="Excellent"] <- 5
#dta141$HEALTH[dta141$QD2=="Very good"] <- 4
#dta141$HEALTH[dta141$QD2=="Good"] <- 3
#dta141$HEALTH[dta141$QD2=="Only fair"] <- 2
#dta141$HEALTH[dta141$QD2=="Poor"] <- 1

#dta141$HEALTH <- NA

dta141$SAWAD <- NA
dta141$SAWADPOS <- NA
dta141$SAWADNEG <- NA
dta141$SAWADBOTH <- NA

dta141$SSTATE <- dta141$STATE

dta141$MALE <- 1*(dta141$SEX=="Male")

dta141$NUMBER <- 141

dta141$MONTH <- 78

dta141$MARKET <- 0
dta141$MARKET[dta141$Q26=="From healthcare.gov or [STATE MARKETPLACE NAME]"]<-1
dta141$MARKET[dta141$Q26=="Through an insurance agent or broker"
              & dta141$Q27=="Marketplace plan"]<-1

dta141$SELFINSURE <- 0
dta141$SELFINSURE[dta141$QD4A=="Plan you purchased yourself"]<-1

dta141$EMPLINSURE <- 0
dta141$EMPLINSURE[dta141$QD4A=="Plan through your employer"]<-1
dta141$EMPLINSURE[dta141$QD4A=="Plan through your spouse's employer"]<-1

dta141$PREEXIST <- NA

#sort(table(dta141$Q2CD[dta141$FAVOR==1]))/sum(sort(table(dta141$Q2CD[dta141$FAVOR==1])))

###lout141a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta141)
##summary(#lout141a)
###mf141a <- model.frame(#lout141a)

#### full data
#nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
##mf141a2 <- subsetn(dta141,select=nms)

###lout141b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta141)
##summary(#lout141b)
###mf141b <- model.frame(#lout141b)

#lout141d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta141)
#summary(#lout141d)
##fv141d <- model.frame(#lout141d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv141a2 <- subsetn(dta141,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s141 <- subsetn(dta141,select=masterlist, subset=T)

##### June 2015
dta140 <- read.por.upper("hni140.por",to.data.frame=T)


dta140$INCOME <- NA
dta140$INCOME[dta140$QD14=="Less than $20,000"] <- 10
dta140$INCOME[dta140$QD14=="$20,000 to less than $30,000"] <- 25
dta140$INCOME[dta140$QD14=="$30,000 to less than $40,000"] <- 35
dta140$INCOME[dta140$QD14=="$40,000 to less than $50,000"] <- 45
dta140$INCOME[dta140$QD14=="$50,000 to less than $75,000"] <- 62.5
dta140$INCOME[dta140$QD14=="$75,000 to less than $90,000"] <- 82.5
dta140$INCOME[dta140$QD14=="$90,000 to less than $100,000"] <- 95
dta140$INCOME[dta140$QD14=="$100,000 or more"] <- 200

dta140$HISP2 <- dta140$HISP
dta140$HISP <- (dta140$HISP2=="Yes")*1

dta140$EDUC <- NA
dta140$EDUC[dta140$EDUC2=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta140$EDUC[dta140$EDUC2=="High school incomplete (Grades 9-11 or Grade 12 with no diploma)"] <- 10
dta140$EDUC[dta140$EDUC2=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta140$EDUC[dta140$EDUC2=="Some college, no degree (includes some community college)"] <- 13
dta140$EDUC[dta140$EDUC2=="Two year associate degree from a college or university"] <- 14
dta140$EDUC[dta140$EDUC2=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta140$EDUC[dta140$EDUC2=="Some postgraduate or professional schooling, no postgraduate degree"] <- 17
dta140$EDUC[dta140$EDUC2=="Post-graduate or professional degree, including master's, doctorate, medical, or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta140$PID <- NA
dta140$PID[dta140$QD8=="Democrat"] <- 1
dta140$PID[dta140$QD8 %in% c("Independent","Or what (includes Other and None)")] <- 2
dta140$PID[dta140$QD8=="Republican"] <- 3

dta140$PID5 <- NA
dta140$PID5[dta140$PID==1] <- 1
dta140$PID5[dta140$QD8A=="Democratic"] <- 2
dta140$PID5[dta140$QD8A %in% c("(DO NOT READ) Independent/don't lean to either party", "(DO NOT READ) Other party", "(DO NOT READ) Don't know/Refused")] <- 3
dta140$PID5[dta140$QD8A=="Republican"] <- 4
dta140$PID5[dta140$PID==3] <- 5


dta140$BETPER <- NA
dta140$BETPER[dta140$Q4=="Helped"] <- 3
dta140$BETPER[dta140$Q4=="(DO NOT READ) Don't know/Refused"] <- 2
dta140$BETPER[dta140$Q4=="(DO NOT READ) Both helped and hurt"] <- 2
dta140$BETPER[dta140$Q4=="No direct impact"] <- 2
dta140$BETPER[dta140$Q4=="Hurt"] <- 1

dta140$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta140$SUPPORT <- NA
#dta140$SUPPORT[dta140$Q1=="Strongly support"] <- 4
#dta140$SUPPORT[dta140$Q1=="Somewhat support"] <- 3
#dta140$SUPPORT[dta140$Q1=="Somewhat oppose"] <- 2
#dta140$SUPPORT[dta140$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta140$BLACK <- (dta140$RACE=="Black or African-American")*1
dta140$ASIAN <- (dta140$RACE=="Asian")*1
dta140$OTHER <- (dta140$RACE=="Other or mixed race (SPECIFY)")*1

dta140$AGE <- dta140$AGE
dta140$AGE[dta140$AGE==99] <- NA
dta140$MEDICARE <- (dta140$AGE > 64)*1


dta140$COVERED <- (dta140$QD4=="Covered by health insurance")*1


dta140$IDEO <- NA
dta140$IDEO[dta140$QD8B=="Liberal"] <- 3
dta140$IDEO[dta140$QD8B=="Moderate"] <- 2
dta140$IDEO[dta140$QD8B=="Conservative"] <- 1

dta140$FAVOR <- NA
dta140$FAVOR[dta140$Q1=="Very favorable"] <- 4
dta140$FAVOR[dta140$Q1=="Somewhat favorable"] <- 3
dta140$FAVOR[dta140$Q1=="Somewhat unfavorable"] <- 2
dta140$FAVOR[dta140$Q1=="Very unfavorable"] <- 1

# Question Still Not Asked
dta140$SELFEMPLOY <- NA
#dta140$SELFEMPLOY[dta140$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta140$RETIRED <- 0
dta140$RETIRED[dta140$QD3=="Retired"] <- 1

dta140$MEDICARESR <- 0
dta140$MEDICARESR <- 1*(dta140$QD4A=="Medicare")
dta140$MEDICARESR[dta140$QD4A %in% c(NA)] <- 0

dta140$MEDICAID <- 0
dta140$MEDICAID <- 1*(dta140$QD4A=="Medicaid/[STATE-SPECIFIC MEDICAID NAME]")
dta140$MEDICAID[dta140$QD4A %in% c(NA)] <- 0


dta140$HEALTH <- NA
#dta140$HEALTH[dta140$QD2=="Excellent"] <- 5
#dta140$HEALTH[dta140$QD2=="Very good"] <- 4
#dta140$HEALTH[dta140$QD2=="Good"] <- 3
#dta140$HEALTH[dta140$QD2=="Only fair"] <- 2
#dta140$HEALTH[dta140$QD2=="Poor"] <- 1

#dta140$HEALTH <- NA

dta140$SAWAD <- NA
dta140$SAWADPOS <- NA
dta140$SAWADNEG <- NA
dta140$SAWADBOTH <- NA

dta140$SSTATE <- dta140$STATE

dta140$MALE <- 1*(dta140$SEX=="Male")

dta140$NUMBER <- 140

dta140$MARKET <- 0
dta140$MARKET[dta140$Q9=="From healthcare.gov or [STATE MARKETPLACE NAME]"]<-1
dta140$MARKET[dta140$Q9=="Through an insurance agent or broker"
              & dta140$Q27=="Marketplace plan"]<-1

dta140$MONTH <- 77

dta140$SELFINSURE <- 0
dta140$SELFINSURE[dta140$QD4A=="Plan you purchased yourself"]<-1

dta140$EMPLINSURE <- 0
dta140$EMPLINSURE[dta140$QD4A=="Plan through your employer"]<-1
dta140$EMPLINSURE[dta140$QD4A=="Plan through your spouse's employer"]<-1

dta140$PREEXIST <- NA

#sort(table(dta140$Q2CD[dta140$FAVOR==1]))/sum(sort(table(dta140$Q2CD[dta140$FAVOR==1])))

###lout140a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta140)
##summary(#lout140a)
###mf140a <- model.frame(#lout140a)

#### full data
#nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
##mf140a2 <- subsetn(dta140,select=nms)

###lout140b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta140)
##summary(#lout140b)
###mf140b <- model.frame(#lout140b)

#lout140d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta140)
#summary(#lout140d)
##fv140d <- model.frame(#lout140d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv140a2 <- subsetn(dta140,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s140 <- subsetn(dta140,select=masterlist, subset=T)

##### April-May 2015?
dta139 <- read.por.upper("hni139.por",to.data.frame=T)


dta139$INCOME <- NA
dta139$INCOME[dta139$QD14=="Less than $20,000"] <- 10
dta139$INCOME[dta139$QD14=="$20,000 to less than $30,000"] <- 25
dta139$INCOME[dta139$QD14=="$30,000 to less than $40,000"] <- 35
dta139$INCOME[dta139$QD14=="$40,000 to less than $50,000"] <- 45
dta139$INCOME[dta139$QD14=="$50,000 to less than $75,000"] <- 62.5
dta139$INCOME[dta139$QD14=="$75,000 to less than $90,000"] <- 82.5
dta139$INCOME[dta139$QD14=="$90,000 to less than $100,000"] <- 95
dta139$INCOME[dta139$QD14=="$100,000 or more"] <- 200

dta139$HISP2 <- dta139$HISP
dta139$HISP <- (dta139$HISP2=="Yes")*1

dta139$EDUC <- NA
dta139$EDUC[dta139$EDUC2=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta139$EDUC[dta139$EDUC2=="High school incomplete (Grades 9-11 or Grade 12 with no diploma)"] <- 10
dta139$EDUC[dta139$EDUC2=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta139$EDUC[dta139$EDUC2=="Some college, no degree (includes some community college)"] <- 13
dta139$EDUC[dta139$EDUC2=="Two year associate degree from a college or university"] <- 14
dta139$EDUC[dta139$EDUC2=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta139$EDUC[dta139$EDUC2=="Some postgraduate or professional schooling, no postgraduate degree"] <- 17
dta139$EDUC[dta139$EDUC2=="Post-graduate or professional degree, including master's, doctorate, medical, or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta139$PID <- NA
dta139$PID[dta139$QD8=="Democrat"] <- 1
dta139$PID[dta139$QD8 %in% c("Independent","Or what (includes Other and None)")] <- 2
dta139$PID[dta139$QD8=="Republican"] <- 3

dta139$PID5 <- NA
dta139$PID5[dta139$PID==1] <- 1
dta139$PID5[dta139$QD8A=="Democratic"] <- 2
dta139$PID5[dta139$QD8A %in% c("(DO NOT READ) Independent/don't lean to either party", "(DO NOT READ) Other party", "(DO NOT READ) Don't know/Refused")] <- 3
dta139$PID5[dta139$QD8A=="Republican"] <- 4
dta139$PID5[dta139$PID==3] <- 5

dta139$BETPER <- NA
dta139$BETPER[dta139$Q3=="Helped"] <- 3
dta139$BETPER[dta139$Q3=="(DO NOT READ) Don't know/Refused"] <- 2
dta139$BETPER[dta139$Q3=="(DO NOT READ) Both helped and hurt"] <- 2
dta139$BETPER[dta139$Q3=="No direct impact"] <- 2
dta139$BETPER[dta139$Q3=="Hurt"] <- 1

dta139$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta139$SUPPORT <- NA
#dta139$SUPPORT[dta139$Q1=="Strongly support"] <- 4
#dta139$SUPPORT[dta139$Q1=="Somewhat support"] <- 3
#dta139$SUPPORT[dta139$Q1=="Somewhat oppose"] <- 2
#dta139$SUPPORT[dta139$Q1=="Strongly oppose"] <- 1

dta139$BLACK <- (dta139$RACE=="Black or African-American")*1
dta139$ASIAN <- (dta139$RACE=="Asian")*1
dta139$OTHER <- (dta139$RACE=="Other or mixed race (SPECIFY)")*1

dta139$AGE <- dta139$AGE
dta139$AGE[dta139$AGE==99] <- NA
dta139$MEDICARE <- (dta139$AGE > 64)*1


dta139$COVERED <- (dta139$QD4=="Covered by health insurance")*1


dta139$IDEO <- NA
dta139$IDEO[dta139$QD8B=="Liberal"] <- 3
dta139$IDEO[dta139$QD8B=="Moderate"] <- 2
dta139$IDEO[dta139$QD8B=="Conservative"] <- 1

dta139$FAVOR <- NA
dta139$FAVOR[dta139$Q1=="Very favorable"] <- 4
dta139$FAVOR[dta139$Q1=="Somewhat favorable"] <- 3
dta139$FAVOR[dta139$Q1=="Somewhat unfavorable"] <- 2
dta139$FAVOR[dta139$Q1=="Very unfavorable"] <- 1

# Question Still Not Asked
dta139$SELFEMPLOY <- NA
#dta139$SELFEMPLOY[dta139$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta139$RETIRED <- 0
dta139$RETIRED[dta139$QD3=="Retired"] <- 1

dta139$MEDICARESR <- 0
dta139$MEDICARESR <- 1*(dta139$QD4A=="Medicare")
dta139$MEDICARESR[dta139$QD4A %in% c(NA)] <- 0

dta139$MEDICAID <- 0
dta139$MEDICAID <- 1*(dta139$QD4A=="Medicaid/[STATE-SPECIFIC MEDICAID NAME]")
dta139$MEDICAID[dta139$QD4A %in% c(NA)] <- 0


dta139$HEALTH <- NA
#dta139$HEALTH[dta139$QD2=="Excellent"] <- 5
#dta139$HEALTH[dta139$QD2=="Very good"] <- 4
#dta139$HEALTH[dta139$QD2=="Good"] <- 3
#dta139$HEALTH[dta139$QD2=="Only fair"] <- 2
#dta139$HEALTH[dta139$QD2=="Poor"] <- 1

#dta139$HEALTH <- NA

dta139$SAWAD <- NA
dta139$SAWADPOS <- NA
dta139$SAWADNEG <- NA
dta139$SAWADBOTH <- NA

dta139$SSTATE <- dta139$STATE

dta139$MALE <- 1*(dta139$SEX=="Male")

dta139$NUMBER <- 139

dta139$MONTH <- 76

dta139$MARKET <- 0
dta139$MARKET[dta139$Q9=="From healthcare.gov or [STATE MARKETPLACE NAME]"]<-1
dta139$MARKET[dta139$Q9=="Through an insurance agent or broker"
              & dta139$Q10=="Marketplace plan"]<-1

dta139$SELFINSURE <- 0
dta139$SELFINSURE[dta139$QD4A=="Plan you purchased yourself"]<-1

dta139$EMPLINSURE <- 0
dta139$EMPLINSURE[dta139$QD4A=="Plan through your employer"]<-1
dta139$EMPLINSURE[dta139$QD4A=="Plan through your spouse's employer"]<-1

dta139$PREEXIST <- NA

#sort(table(dta139$Q2CD[dta139$FAVOR==1]))/sum(sort(table(dta139$Q2CD[dta139$FAVOR==1])))

###lout139a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta139)
##summary(#lout139a)
###mf139a <- model.frame(#lout139a)

#### full data
#nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
##mf139a2 <- subsetn(dta139,select=nms)

###lout139b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta139)
##summary(#lout139b)
###mf139b <- model.frame(#lout139b)

#lout139d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta139)
#summary(#lout139d)
##fv139d <- model.frame(#lout139d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv139a2 <- subsetn(dta139,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s139 <- subsetn(dta139,select=masterlist, subset=T)


##### March 2015
dta138 <- read.csv.lower("hni138.csv")

dta138$INCOME <- NA
dta138$INCOME[dta138$qd14==1] <- 10
dta138$INCOME[dta138$qd14==2] <- 25
dta138$INCOME[dta138$qd14==3] <- 35
dta138$INCOME[dta138$qd14==4] <- 45
dta138$INCOME[dta138$qd14==5] <- 62.5
dta138$INCOME[dta138$qd14==6] <- 82.5
dta138$INCOME[dta138$qd14==7] <- 95
dta138$INCOME[dta138$qd14==8] <- 200

dta138$HISP2 <- dta138$qd12
dta138$HISP <- (dta138$HISP2==1)*1

dta138$EDUC <- NA
dta138$EDUC[dta138$qd11==1] <- 6
dta138$EDUC[dta138$qd11==2] <- 10
dta138$EDUC[dta138$qd11==3] <- 12
dta138$EDUC[dta138$qd11==4] <- 13
dta138$EDUC[dta138$qd11==5] <- 14
dta138$EDUC[dta138$qd11==6] <- 16
dta138$EDUC[dta138$qd11==7] <- 17
dta138$EDUC[dta138$qd11==8] <- 19

dta138$PID <- NA
dta138$PID[dta138$qd8==2] <- 1
dta138$PID[dta138$qd8>=3 & dta138$qd8<=4] <- 2
dta138$PID[dta138$qd8==1] <- 3

dta138$PID5 <- NA
dta138$PID5[dta138$PID==1] <- 1
dta138$PID5[dta138$qd8a==1] <- 2
dta138$PID5[dta138$qd8a %in%  c(3, 4, 9)] <- 3
dta138$PID5[dta138$qd8a==2] <- 4
dta138$PID5[dta138$PID==3] <- 5


dta138$BETPER <- NA
dta138$BETPER[dta138$q5=="Helped"] <- 3
dta138$BETPER[dta138$q5=="(DO NOT READ) Don't know/Refused"] <- 2
dta138$BETPER[dta138$q5=="(DO NOT READ) Both helped and hurt"] <- 2
dta138$BETPER[dta138$q5=="No direct impact"] <- 2
dta138$BETPER[dta138$q5=="Hurt"] <- 1

dta138$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta138$SUPPORT <- NA
#dta138$SUPPORT[dta138$Q1=="Strongly support"] <- 4
#dta138$SUPPORT[dta138$Q1=="Somewhat support"] <- 3
#dta138$SUPPORT[dta138$Q1=="Somewhat oppose"] <- 2
#dta138$SUPPORT[dta138$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta138$BLACK <- (dta138$qd13==2)*1
dta138$ASIAN <- (dta138$qd13==3)*1
dta138$OTHER <- (dta138$qd13==4)*1

dta138$AGE <- dta138$qd5
dta138$AGE[dta138$AGE==99] <- NA
dta138$MEDICARE <- (dta138$AGE > 64)*1


dta138$COVERED <- (dta138$qd4==1)*1


dta138$IDEO <- NA
dta138$IDEO[dta138$qd8b==1] <- 3
dta138$IDEO[dta138$qd8b==2] <- 2
dta138$IDEO[dta138$qd8b==3] <- 1

dta138$FAVOR <- NA
dta138$FAVOR[dta138$q1==1] <- 4
dta138$FAVOR[dta138$q1==2] <- 3
dta138$FAVOR[dta138$q1==3] <- 2
dta138$FAVOR[dta138$q1==4] <- 1

# Question Still Not Asked
dta138$SELFEMPLOY <- NA
#dta138$SELFEMPLOY[dta138$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta138$RETIRED <- 0
dta138$RETIRED[dta138$qd3==6] <- 1

dta138$MEDICARESR <- 0
dta138$MEDICARESR <- 1*(dta138$qd4a==4)
dta138$MEDICARESR[dta138$COVERED==0] <- 0

dta138$MEDICAID <- 0
dta138$MEDICAID <- 1*(dta138$qd4a==5)
dta138$MEDICAID[dta138$COVERED==0] <- 0


dta138$HEALTH <- NA

dta138$SAWAD <- NA
dta138$SAWADPOS <- NA
dta138$SAWADNEG <- NA
dta138$SAWADBOTH <- NA

dta138$SSTATE <- dta138$state
dta138$STATE <- dta138$state

dta138$MALE <- 1*(dta138$qd1==1)

dta138$NUMBER <- 138

dta138$MONTH <- 74

dta138$MARKET <- 0
dta138$MARKET[dta138$q34==2]<-1


dta138$SELFINSURE <- 0
dta138$SELFINSURE[dta138$qd4a==3]<-1
dta138$SELFINSURE[dta138$COVERED==0] <- 0

dta138$EMPLINSURE <- 0
dta138$EMPLINSURE[dta138$qd4a==1]<-1
dta138$EMPLINSURE[dta138$qd4a==2]<-1
dta138$EMPLINSURE[dta138$COVERED==0] <- 0

dta138$PREEXIST <- NA
dta138$REGISTERED <- NA

#sort(table(dta138$Q2CD[dta138$FAVOR==1]))/sum(sort(table(dta138$Q2CD[dta138$FAVOR==1])))

#lout138a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta138)
#summary(#lout138a)
##mf138a <- model.frame(#lout138a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf138a2 <- subsetn(dta138,select=nms)

#lout138b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta138)
#summary(#lout138b)
##mf138b <- model.frame(#lout138b)

#lout138d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta138)
#summary(#lout138d)
##fv138d <- model.frame(#lout138d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv138a2 <- subsetn(dta138,select=fvnms)

dta138$PSRAID <- dta138$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s138 <- subsetn(dta138,select=masterlist, subset=T)

##### January 2015
dta137 <- read.por.upper("hni137.por",to.data.frame=T)


dta137$INCOME <- NA
dta137$INCOME[dta137$QD14=="Less than $20,000"] <- 10
dta137$INCOME[dta137$QD14=="$20,000 to less than $30,000"] <- 25
dta137$INCOME[dta137$QD14=="$30,000 to less than $40,000"] <- 35
dta137$INCOME[dta137$QD14=="$40,000 to less than $50,000"] <- 45
dta137$INCOME[dta137$QD14=="$50,000 to less than $75,000"] <- 62.5
dta137$INCOME[dta137$QD14=="$75,000 to less than $90,000"] <- 82.5
dta137$INCOME[dta137$QD14=="$90,000 to less than $100,000"] <- 95
dta137$INCOME[dta137$QD14=="$100,000 or more"] <- 200

dta137$HISP <- (dta137$QD12=="Yes")*1

dta137$EDUC <- NA
dta137$EDUC[dta137$QD11=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta137$EDUC[dta137$QD11=="High school incomplete (Grades 9-11 or Grade 12 with no diploma)"] <- 10
dta137$EDUC[dta137$QD11=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta137$EDUC[dta137$QD11=="Some college, no degree (includes some community college)"] <- 13
dta137$EDUC[dta137$QD11=="Two year associate degree from a college or university"] <- 14
dta137$EDUC[dta137$QD11=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta137$EDUC[dta137$QD11=="Some postgraduate or professional schooling, no postgraduate degree"] <- 17
dta137$EDUC[dta137$QD11=="Postgraduate or professional degree, including master's, doctorate, medical or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta137$PID <- NA
dta137$PID[dta137$QD8=="Democrat"] <- 1
dta137$PID[dta137$QD8 %in% c("Independent","Or what?")] <- 2
dta137$PID[dta137$QD8=="Republican"] <- 3

dta137$PID5 <- NA
dta137$PID5[dta137$PID==1] <- 1
dta137$PID5[dta137$QD8A=="Democratic"] <- 2
dta137$PID5[dta137$QD8A %in% c("(DO NOT READ) Independent/don't lean to either party", "(DO NOT READ) Other party", "(DO NOT READ) Don't know/Refused")] <- 3
dta137$PID5[dta137$QD8A=="Republican"] <- 4
dta137$PID5[dta137$PID==3] <- 5

dta137$BETPER <- NA
dta137$BETPER[dta137$Q12=="Helped"] <- 3
dta137$BETPER[dta137$Q12=="(DO NOT READ) Don't know/Refused"] <- 2
dta137$BETPER[dta137$Q12=="(DO NOT READ) Both helped and hurt"] <- 2
dta137$BETPER[dta137$Q12=="No direct impact"] <- 2
dta137$BETPER[dta137$Q12=="Hurt"] <- 1

dta137$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta137$SUPPORT <- NA
#dta137$SUPPORT[dta137$Q1=="Strongly support"] <- 4
#dta137$SUPPORT[dta137$Q1=="Somewhat support"] <- 3
#dta137$SUPPORT[dta137$Q1=="Somewhat oppose"] <- 2
#dta137$SUPPORT[dta137$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta137$BLACK <- (dta137$QD13=="Black or African-American")*1
dta137$ASIAN <- (dta137$QD13=="Asian")*1
dta137$OTHER <- (dta137$QD13=="Other or mixed race (SPECIFY)")*1

dta137$AGE <- dta137$QD5
dta137$AGE[dta137$AGE==99] <- NA
dta137$MEDICARE <- (dta137$AGE > 64)*1


dta137$COVERED <- (dta137$QD4=="Covered by health insurance")*1


dta137$IDEO <- NA
dta137$IDEO[dta137$QD8B=="Liberal"] <- 3
dta137$IDEO[dta137$QD8B=="Moderate"] <- 2
dta137$IDEO[dta137$QD8B=="Conservative"] <- 1

dta137$FAVOR <- NA
dta137$FAVOR[dta137$Q1=="Very favorable"] <- 4
dta137$FAVOR[dta137$Q1=="Somewhat favorable"] <- 3
dta137$FAVOR[dta137$Q1=="Somewhat unfavorable"] <- 2
dta137$FAVOR[dta137$Q1=="Very unfavorable"] <- 1

# Question Still Not Asked
dta137$SELFEMPLOY <- NA
#dta137$SELFEMPLOY[dta137$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta137$RETIRED <- 0
dta137$RETIRED[dta137$QD3=="Retired"] <- 1

dta137$MEDICARESR <- 0
dta137$MEDICARESR <- 1*(dta137$QD4A=="Medicare")
dta137$MEDICARESR[dta137$QD4A %in% c(NA)] <- 0

dta137$MEDICAID <- 0
dta137$MEDICAID <- 1*(dta137$QD4A=="Medicaid/[STATE-SPECIFIC MEDICAID NAME]")
dta137$MEDICAID[dta137$QD4A %in% c(NA)] <- 0


dta137$HEALTH <- NA
#dta137$HEALTH[dta137$QD2=="Excellent"] <- 5
#dta137$HEALTH[dta137$QD2=="Very good"] <- 4
#dta137$HEALTH[dta137$QD2=="Good"] <- 3
#dta137$HEALTH[dta137$QD2=="Only fair"] <- 2
#dta137$HEALTH[dta137$QD2=="Poor"] <- 1

#dta137$HEALTH <- NA

dta137$SAWAD <- NA
dta137$SAWADPOS <- NA
dta137$SAWADNEG <- NA
dta137$SAWADBOTH <- NA

dta137$SSTATE <- dta137$STATE

dta137$MALE <- 1*(dta137$QD1=="Male")

dta137$NUMBER <- 137

dta137$MONTH <- 72

dta137$MARKET <- 0
dta137$MARKET[dta137$Q30=="From healthcare.gov or [STATE MARKETPLACE NAME]"]<-1
dta137$MARKET[dta137$Q30=="Through an insurance agent or broker"
              & dta137$Q31=="Plan purchased from a state or federal marketplace"]<-1

dta137$SELFINSURE <- 0
dta137$SELFINSURE[dta137$QD4A=="Plan you purchased yourself"]<-1

dta137$EMPLINSURE <- 0
dta137$EMPLINSURE[dta137$QD4A=="Plan through your employer"]<-1
dta137$EMPLINSURE[dta137$QD4A=="Plan through your spouse's employer"]<-1

dta137$PREEXIST <- NA

#sort(table(dta137$Q2CD[dta137$FAVOR==1]))/sum(sort(table(dta137$Q2CD[dta137$FAVOR==1])))

###lout137a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta137)
##summary(#lout137a)
###mf137a <- model.frame(#lout137a)

#### full data
#nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
##mf137a2 <- subsetn(dta137,select=nms)

###lout137b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta137)
##summary(#lout137b)
###mf137b <- model.frame(#lout137b)

#lout137d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta137)
#summary(#lout137d)
##fv137d <- model.frame(#lout137d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv137a2 <- subsetn(dta137,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s137 <- subsetn(dta137,select=masterlist, subset=T)



##### December 2014
dta136 <- read.por.upper("hni136.por",to.data.frame=T)


dta136$INCOME <- NA
dta136$INCOME[dta136$QD14=="Less than $20,000"] <- 10
dta136$INCOME[dta136$QD14=="$20,000 to less than $30,000"] <- 25
dta136$INCOME[dta136$QD14=="$30,000 to less than $40,000"] <- 35
dta136$INCOME[dta136$QD14=="$40,000 to less than $50,000"] <- 45
dta136$INCOME[dta136$QD14=="$50,000 to less than $75,000"] <- 62.5
dta136$INCOME[dta136$QD14=="$75,000 to less than $90,000"] <- 82.5
dta136$INCOME[dta136$QD14=="$90,000 to less than $100,000"] <- 95
dta136$INCOME[dta136$QD14=="$100,000 or more"] <- 200

dta136$HISP <- (dta136$QD12=="Yes")*1

dta136$EDUC <- NA
dta136$EDUC[dta136$QD11=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta136$EDUC[dta136$QD11=="High school incomplete (Grades 9-11 or Grade 12 with no diploma)"] <- 10
dta136$EDUC[dta136$QD11=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta136$EDUC[dta136$QD11=="Some college, no degree (includes some community college)"] <- 13
dta136$EDUC[dta136$QD11=="Two year associate degree from a college or university"] <- 14
dta136$EDUC[dta136$QD11=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta136$EDUC[dta136$QD11=="Some postgraduate or professional schooling, no postgraduate degree"] <- 17
dta136$EDUC[dta136$QD11=="Postgraduate or professional degree, including master's, doctorate, medical or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta136$PID <- NA
dta136$PID[dta136$QD8=="Democrat"] <- 1
dta136$PID[dta136$QD8 %in% c("Independent","Or what?")] <- 2
dta136$PID[dta136$QD8=="Republican"] <- 3

dta136$PID5 <- NA
dta136$PID5[dta136$PID==1] <- 1
dta136$PID5[dta136$QD8A=="Democratic"] <- 2
dta136$PID5[dta136$QD8A %in% c("(DO NOT READ) Independent/don't lean to either party", "(DO NOT READ) Other party", "(DO NOT READ) Don't know/Refused")] <- 3
dta136$PID5[dta136$QD8A=="Republican"] <- 4
dta136$PID5[dta136$PID==3] <- 5


dta136$BETPER <- NA
dta136$BETPER[dta136$Q4A=="Better off"] <- 3
dta136$BETPER[dta136$Q4A=="No difference"] <- 2
dta136$BETPER[dta136$Q4A=="(DO NOT READ) Don't know/ Refused"] <- 2
dta136$BETPER[dta136$Q4A=="Worse off"] <- 1

dta136$BETCOU <- NA
dta136$BETCOU[dta136$Q4B=="Better off"] <- 3
dta136$BETCOU[dta136$Q4B=="No difference"] <- 2
dta136$BETCOU[dta136$Q4B=="(DO NOT READ) Don't know/ Refused"] <- 2
dta136$BETCOU[dta136$Q4B=="Worse off"] <- 1

# NOTE: var replaced with FAVOR var.
dta136$SUPPORT <- NA
#dta136$SUPPORT[dta136$Q1=="Strongly support"] <- 4
#dta136$SUPPORT[dta136$Q1=="Somewhat support"] <- 3
#dta136$SUPPORT[dta136$Q1=="Somewhat oppose"] <- 2
#dta136$SUPPORT[dta136$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta136$BLACK <- (dta136$QD13=="Black or African-American")*1
dta136$ASIAN <- (dta136$QD13=="Asian")*1
dta136$OTHER <- (dta136$QD13=="Other or mixed race (SPECIFY)")*1

dta136$AGE <- dta136$QD5
dta136$AGE[dta136$AGE==99] <- NA
dta136$MEDICARE <- (dta136$AGE > 64)*1


dta136$COVERED <- (dta136$QD4=="Covered by health insurance")*1


dta136$IDEO <- NA
dta136$IDEO[dta136$QD8B=="Liberal"] <- 3
dta136$IDEO[dta136$QD8B=="Moderate"] <- 2
dta136$IDEO[dta136$QD8B=="Conservative"] <- 1

dta136$FAVOR <- NA
dta136$FAVOR[dta136$Q1=="Very favorable"] <- 4
dta136$FAVOR[dta136$Q1=="Somewhat favorable"] <- 3
dta136$FAVOR[dta136$Q1=="Somewhat unfavorable"] <- 2
dta136$FAVOR[dta136$Q1=="Very unfavorable"] <- 1

# Question Still Not Asked
dta136$SELFEMPLOY <- NA
#dta136$SELFEMPLOY[dta136$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta136$RETIRED <- 0
dta136$RETIRED[dta136$QD3=="Retired"] <- 1

dta136$MEDICARESR <- 0
dta136$MEDICARESR <- 1*(dta136$QD4A=="Medicare")
dta136$MEDICARESR[dta136$QD4A %in% c(NA)] <- 0

dta136$MEDICAID <- 0
dta136$MEDICAID <- 1*(dta136$QD4A=="Medicaid/[STATE-SPECIFIC MEDICAID NAME]")
dta136$MEDICAID[dta136$QD4A %in% c(NA)] <- 0


dta136$HEALTH <- NA
#dta136$HEALTH[dta136$QD2=="Excellent"] <- 5
#dta136$HEALTH[dta136$QD2=="Very good"] <- 4
#dta136$HEALTH[dta136$QD2=="Good"] <- 3
#dta136$HEALTH[dta136$QD2=="Only fair"] <- 2
#dta136$HEALTH[dta136$QD2=="Poor"] <- 1

#dta136$HEALTH <- NA

dta136$SAWAD <- NA
dta136$SAWADPOS <- NA
dta136$SAWADNEG <- NA
dta136$SAWADBOTH <- NA

dta136$SSTATE <- dta136$STATE

dta136$MALE <- 1*(dta136$QD1=="Male")

dta136$NUMBER <- 136

dta136$MONTH <- 71

dta136$MARKET <- 0
dta136$MARKET[dta136$Q22=="From healthcare.gov or [STATE MARKETPLACE NAME]"]<-1
dta136$MARKET[dta136$Q22=="Through an insurance agent or broker"
              & dta136$Q23=="Plan purchased from a state or federal marketplace"]<-1

dta136$SELFINSURE <- 0
dta136$SELFINSURE[dta136$QD4A=="Plan you purchased yourself"]<-1

dta136$EMPLINSURE <- 0
dta136$EMPLINSURE[dta136$QD4A=="Plan through your employer"]<-1
dta136$EMPLINSURE[dta136$QD4A=="Plan through your spouse's employer"]<-1

dta136$PREEXIST <- NA

dta136$REGISTERED <- NA

#sort(table(dta136$Q2CD[dta136$FAVOR==1]))/sum(sort(table(dta136$Q2CD[dta136$FAVOR==1])))

#lout136a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta136)
#summary(#lout136a)
##mf136a <- model.frame(#lout136a)



#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
##mf136a2 <- subsetn(dta136,select=nms)

#lout136b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta136)
#summary(#lout136b)
##mf136b <- model.frame(#lout136b)

#lout136d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta136)
#summary(#lout136d)
##fv136d <- model.frame(#lout136d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv136a2 <- subsetn(dta136,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s136 <- subsetn(dta136,select=masterlist, subset=T)



##### November 2014
dta135 <- read.por.upper("hni135.por",to.data.frame=T)

dta135$INCOME <- NA
dta135$INCOME[dta135$QD14=="Less than $20,000"] <- 10
dta135$INCOME[dta135$QD14=="$20,000 to less than $30,000"] <- 25
dta135$INCOME[dta135$QD14=="$30,000 to less than $40,000"] <- 35
dta135$INCOME[dta135$QD14=="$40,000 to less than $50,000"] <- 45
dta135$INCOME[dta135$QD14=="$50,000 to less than $75,000"] <- 62.5
dta135$INCOME[dta135$QD14=="$75,000 to less than $90,000"] <- 82.5
dta135$INCOME[dta135$QD14=="$90,000 to less than $100,000"] <- 95
dta135$INCOME[dta135$QD14=="$100,000 or more"] <- 200

dta135$HISP <- (dta135$QD12=="Yes")*1

dta135$EDUC <- NA
dta135$EDUC[dta135$QD11=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta135$EDUC[dta135$QD11=="High school incomplete (Grades 9-11 or Grade 12 with no diploma)"] <- 10
dta135$EDUC[dta135$QD11=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta135$EDUC[dta135$QD11=="Some college, no degree (includes some community college)"] <- 13
dta135$EDUC[dta135$QD11=="Two year associate degree from a college or university"] <- 14
dta135$EDUC[dta135$QD11=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta135$EDUC[dta135$QD11=="Some postgraduate or professional schooling, no postgraduate degree"] <- 17
dta135$EDUC[dta135$QD11=="Postgraduate or professional degree, including master's, doctorate, medical or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta135$PID <- NA
dta135$PID[dta135$QD8=="Democrat"] <- 1
dta135$PID[dta135$QD8 %in% c("Independent","Or what?")] <- 2
dta135$PID[dta135$QD8=="Republican"] <- 3

dta135$PID5 <- NA
dta135$PID5[dta135$PID==1] <- 1
dta135$PID5[dta135$QD8A=="Democratic"] <- 2
dta135$PID5[dta135$QD8A %in% c("(DO NOT READ) Independent/don't lean to either party", "(DO NOT READ) Other party", "(DO NOT READ) Don't know/Refused")] <- 3
dta135$PID5[dta135$QD8A=="Republican"] <- 4
dta135$PID5[dta135$PID==3] <- 5

dta135$REGISTERED <- NA
dta135$REGISTERED[dta135$QD9=="Yes"] <- 1
dta135$REGISTERED[dta135$QD9=="No"] <- 2

dta135$VOTED <- NA
dta135$VOTED[dta135$Q1=="Yes, voted"] <- 1
dta135$VOTED[dta135$Q1=="No, did not vote/not registered"] <- 2

dta135$BETPER <- NA
dta135$BETPER[dta135$Q9=="Yes, have benefited"] <- 3
dta135$BETPER[dta135$Q9=="(DO NOT READ) Don't know/Refused"] <- 2
dta135$BETPER[dta135$Q9=="No, have not benefited"] <- 1

dta135$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta135$SUPPORT <- NA
#dta135$SUPPORT[dta135$Q1=="Strongly support"] <- 4
#dta135$SUPPORT[dta135$Q1=="Somewhat support"] <- 3
#dta135$SUPPORT[dta135$Q1=="Somewhat oppose"] <- 2
#dta135$SUPPORT[dta135$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta135$BLACK <- (dta135$QD13=="Black or African-American")*1
dta135$ASIAN <- (dta135$QD13=="Asian")*1
dta135$OTHER <- (dta135$QD13=="Other or mixed race (SPECIFY)")*1

dta135$AGE <- dta135$QD5
dta135$AGE[dta135$AGE==99] <- NA
dta135$MEDICARE <- (dta135$AGE > 64)*1


dta135$COVERED <- (dta135$QD4=="Covered by health insurance")*1


dta135$IDEO <- NA
dta135$IDEO[dta135$QD8B=="Liberal"] <- 3
dta135$IDEO[dta135$QD8B=="Moderate"] <- 2
dta135$IDEO[dta135$QD8B=="Conservative"] <- 1

dta135$FAVOR <- NA
dta135$FAVOR[dta135$Q6=="Very favorable"] <- 4
dta135$FAVOR[dta135$Q6=="Somewhat favorable"] <- 3
dta135$FAVOR[dta135$Q6=="Somewhat unfavorable"] <- 2
dta135$FAVOR[dta135$Q6=="Very unfavorable"] <- 1

# Question Still Not Asked
dta135$SELFEMPLOY <- NA
#dta135$SELFEMPLOY[dta135$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta135$RETIRED <- 0
dta135$RETIRED[dta135$QD3=="Retired"] <- 1

dta135$MEDICARESR <- 0
dta135$MEDICARESR <- 1*(dta135$QD4A=="Medicare")
dta135$MEDICARESR[dta135$QD4A %in% c(NA)] <- 0

dta135$MEDICAID <- 0
dta135$MEDICAID <- 1*(dta135$QD4A=="Medicaid/[STATE-SPECIFIC MEDICAID NAME]")
dta135$MEDICAID[dta135$QD4A %in% c(NA)] <- 0


dta135$HEALTH <- NA
dta135$HEALTH[dta135$QD2=="Excellent"] <- 5
dta135$HEALTH[dta135$QD2=="Very good"] <- 4
dta135$HEALTH[dta135$QD2=="Good"] <- 3
dta135$HEALTH[dta135$QD2=="Only fair"] <- 2
dta135$HEALTH[dta135$QD2=="Poor"] <- 1

dta135$SAWAD <- NA
dta135$SAWADPOS <- NA
dta135$SAWADNEG <- NA
dta135$SAWADBOTH <- NA

dta135$SSTATE <- dta135$STATE

dta135$MALE <- 1*(dta135$QD1=="Male")

dta135$NUMBER <- 135

dta135$MONTH <- 70

dta135$MARKET <- 0
dta135$MARKET[dta135$Q35=="From healthcare.gov or [STATE MARKETPLACE NAME]"]<-1
dta135$MARKET[dta135$Q35=="Through an insurance agent or broker"
              & dta135$Q36=="Plan purchased from a state or federal marketplace"]<-1

dta135$SELFINSURE <- 0
dta135$SELFINSURE[dta135$QD4A=="Plan you purchased yourself"]<-1

dta135$EMPLINSURE <- 0
dta135$EMPLINSURE[dta135$QD4A=="Plan through your employer"]<-1
dta135$EMPLINSURE[dta135$QD4A=="Plan through your spouse's employer"]<-1

dta135$PREEXIST <- NA

#sort(table(dta135$Q2CD[dta135$FAVOR==1]))/sum(sort(table(dta135$Q2CD[dta135$FAVOR==1])))

####lout135a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta135)
###summary(#lout135a)
####mf135a <- model.frame(#lout135a)

#### full data
#nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
##mf135a2 <- subsetn(dta135,select=nms)

####lout135b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta135)
###summary(#lout135b)
####mf135b <- model.frame(#lout135b)

#lout135d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta135)
##summary(#lout135d)
###fv135d <- model.frame(#lout135d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv135a2 <- subsetn(dta135,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s135 <- subsetn(dta135,select=masterlist, subset=T)


##### October 2014
dta134 <- read.csv.lower("hni134.csv")

dta134$INCOME <- NA
dta134$INCOME[dta134$qd14==1] <- 10
dta134$INCOME[dta134$qd14==2] <- 25
dta134$INCOME[dta134$qd14==3] <- 35
dta134$INCOME[dta134$qd14==4] <- 45
dta134$INCOME[dta134$qd14==5] <- 62.5
dta134$INCOME[dta134$qd14==6] <- 82.5
dta134$INCOME[dta134$qd14==7] <- 95
dta134$INCOME[dta134$qd14==8] <- 200

dta134$HISP2 <- dta134$qd12
dta134$HISP <- (dta134$HISP2==1)*1

dta134$EDUC <- NA
dta134$EDUC[dta134$qd11==1] <- 6
dta134$EDUC[dta134$qd11==2] <- 10
dta134$EDUC[dta134$qd11==3] <- 12
dta134$EDUC[dta134$qd11==4] <- 13
dta134$EDUC[dta134$qd11==5] <- 14
dta134$EDUC[dta134$qd11==6] <- 16
dta134$EDUC[dta134$qd11==7] <- 17
dta134$EDUC[dta134$qd11==8] <- 19

dta134$PID <- NA
dta134$PID[dta134$qd8==2] <- 1
dta134$PID[dta134$qd8>=3 & dta134$qd8<=4] <- 2
dta134$PID[dta134$qd8==1] <- 3

dta134$PID5 <- NA
dta134$PID5[dta134$PID==1] <- 1
dta134$PID5[dta134$qd8a==1] <- 2
dta134$PID5[dta134$qd8a %in%  c(3, 4, 9)] <- 3
dta134$PID5[dta134$qd8a==2] <- 4
dta134$PID5[dta134$PID==3] <- 5

dta134$REGISTERED <- NA
dta134$REGISTERED[dta134$QD9=="Yes"] <- 1
dta134$REGISTERED[dta134$QD9=="No"] <- 2


dta134$BETPER <- NA
dta134$BETPER[dta134$Q7=="Yes, have benefited"] <- 3
dta134$BETPER[dta134$Q7=="(DO NOT READ) Don't know/Refused"] <- 2
dta134$BETPER[dta134$Q7=="No, have not benefited"] <- 1


dta134$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta134$SUPPORT <- NA
#dta134$SUPPORT[dta134$Q1=="Strongly support"] <- 4
#dta134$SUPPORT[dta134$Q1=="Somewhat support"] <- 3
#dta134$SUPPORT[dta134$Q1=="Somewhat oppose"] <- 2
#dta134$SUPPORT[dta134$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta134$BLACK <- (dta134$qd13==2)*1
dta134$ASIAN <- (dta134$qd13==3)*1
dta134$OTHER <- (dta134$qd13==4)*1

dta134$AGE <- dta134$qd5
dta134$AGE[dta134$AGE==99] <- NA
dta134$MEDICARE <- (dta134$AGE > 64)*1


dta134$COVERED <- (dta134$qd4==1)*1


dta134$IDEO <- NA
dta134$IDEO[dta134$qd8b==1] <- 3
dta134$IDEO[dta134$qd8b==2] <- 2
dta134$IDEO[dta134$qd8b==3] <- 1

dta134$FAVOR <- NA
dta134$FAVOR[dta134$q1==1] <- 4
dta134$FAVOR[dta134$q1==2] <- 3
dta134$FAVOR[dta134$q1==3] <- 2
dta134$FAVOR[dta134$q1==4] <- 1

# Question Still Not Asked
dta134$SELFEMPLOY <- NA
#dta134$SELFEMPLOY[dta134$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta134$RETIRED <- 0
dta134$RETIRED[dta134$qd3==6] <- 1

dta134$MEDICARESR <- 0
dta134$MEDICARESR <- 1*(dta134$qd4a==4)
dta134$MEDICARESR[dta134$COVERED==0] <- 0

dta134$MEDICAID <- 0
dta134$MEDICAID <- 1*(dta134$qd4a==5)
dta134$MEDICAID[dta134$COVERED==0] <- 0


dta134$HEALTH <- NA
dta134$HEALTH[dta134$qd2==1] <- 5
dta134$HEALTH[dta134$qd2==2] <- 4
dta134$HEALTH[dta134$qd2==3] <- 3
dta134$HEALTH[dta134$qd2==4] <- 2
dta134$HEALTH[dta134$qd2==5] <- 1

dta134$SAWAD <- NA
dta134$SAWADPOS <- NA
dta134$SAWADNEG <- NA
dta134$SAWADBOTH <- NA

dta134$SSTATE <- dta134$state
dta134$STATE <- dta134$state

dta134$MALE <- 1*(dta134$qd1==1)

dta134$NUMBER <- 134

dta134$MONTH <- 69

dta134$MARKET <- 0
dta134$MARKET[dta134$q37==2]<-1


dta134$SELFINSURE <- 0
dta134$SELFINSURE[dta134$qd4a==3]<-1
dta134$SELFINSURE[dta134$COVERED==0] <- 0

dta134$EMPLINSURE <- 0
dta134$EMPLINSURE[dta134$qd4a==1]<-1
dta134$EMPLINSURE[dta134$qd4a==2]<-1
dta134$EMPLINSURE[dta134$COVERED==0] <- 0

dta134$PREEXIST <- NA

#sort(table(dta134$Q2CD[dta134$FAVOR==1]))/sum(sort(table(dta134$Q2CD[dta134$FAVOR==1])))

#lout134a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta134)
##summary(#lout134a)
###mf134a <- model.frame(#lout134a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf134a2 <- subsetn(dta134,select=nms)

#lout134b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta134)
#summary(#lout134b)
##mf134b <- model.frame(#lout134b)

#lout134d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta134)
#summary(#lout134d)
##fv134d <- model.frame(#lout134d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv134a2 <- subsetn(dta134,select=fvnms)

dta134$PSRAID <- dta134$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s134 <- subsetn(dta134,select=masterlist, subset=T)

##### August-September 2014
# NOTE: This dataset was a problem, had to delete observation 240 to get it to work for some reason
dta133 <- read.csv.lower("hni133.csv")

dta133$INCOME <- NA
dta133$INCOME[dta133$qd14==1] <- 10
dta133$INCOME[dta133$qd14==2] <- 25
dta133$INCOME[dta133$qd14==3] <- 35
dta133$INCOME[dta133$qd14==4] <- 45
dta133$INCOME[dta133$qd14==5] <- 62.5
dta133$INCOME[dta133$qd14==6] <- 82.5
dta133$INCOME[dta133$qd14==7] <- 95
dta133$INCOME[dta133$qd14==8] <- 200

dta133$HISP <- (dta133$qd12==1)*1

dta133$EDUC <- NA
dta133$EDUC[dta133$qd11==1] <- 6
dta133$EDUC[dta133$qd11==2] <- 10
dta133$EDUC[dta133$qd11==3] <- 12
dta133$EDUC[dta133$qd11==4] <- 13
dta133$EDUC[dta133$qd11==5] <- 14
dta133$EDUC[dta133$qd11==6] <- 16
dta133$EDUC[dta133$qd11==7] <- 17
dta133$EDUC[dta133$qd11==8] <- 19

dta133$PID <- NA
dta133$PID[dta133$qd8==2] <- 1
dta133$PID[dta133$qd8 %in% c(3,4)] <- 2
dta133$PID[dta133$qd8==1] <- 3

dta133$PID5 <- NA
dta133$PID5[dta133$PID==1] <- 1
dta133$PID5[dta133$qd8a==1] <- 2
dta133$PID5[dta133$qd8a %in%  c(3, 4, 9)] <- 3
dta133$PID5[dta133$qd8a==2] <- 4
dta133$PID5[dta133$PID==3] <- 5

dta133$REGISTERED <- NA
dta133$REGISTERED[dta133$QD9=="Yes"] <- 1
dta133$REGISTERED[dta133$QD9=="No"] <- 2


dta133$BETPER <- NA
dta133$BETPER[dta133$Q11=="Yes, have benefited"] <- 3
dta133$BETPER[dta133$Q11=="(DO NOT READ) Don't know/Refused"] <- 2
dta133$BETPER[dta133$Q11=="No, have not benefited"] <- 1

dta133$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta133$SUPPORT <- NA
#dta133$SUPPORT[dta133$Q1=="Strongly support"] <- 4
#dta133$SUPPORT[dta133$Q1=="Somewhat support"] <- 3
#dta133$SUPPORT[dta133$Q1=="Somewhat oppose"] <- 2
#dta133$SUPPORT[dta133$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta133$BLACK <- (dta133$qd13==2)*1
dta133$ASIAN <- (dta133$qd13==3)*1
dta133$OTHER <- (dta133$qd13==4)*1

dta133$AGE <- as.numeric(dta133$qd5)
dta133$AGE[dta133$AGE==99] <- NA
dta133$MEDICARE <- (dta133$AGE > 64)*1


dta133$COVERED <- (dta133$qd4==1)*1


dta133$IDEO <- NA
dta133$IDEO[dta133$qd8b==1] <- 3
dta133$IDEO[dta133$qd8b==2] <- 2
dta133$IDEO[dta133$qd8b==3] <- 1

dta133$FAVOR <- NA
dta133$FAVOR[dta133$q2==1] <- 4
dta133$FAVOR[dta133$q2==2] <- 3
dta133$FAVOR[dta133$q2==3] <- 2
dta133$FAVOR[dta133$q2==4] <- 1

# Question Still Not Asked
dta133$SELFEMPLOY <- NA
#dta133$SELFEMPLOY[dta133$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta133$RETIRED <- 0
dta133$RETIRED[dta133$qd3==6] <- 1

dta133$MEDICARESR <- 0
dta133$MEDICARESR <- 1*(dta133$qd4a==4)
dta133$MEDICARESR[dta133$qd4a %in% c(NA)] <- 0

dta133$MEDICAID <- 0
dta133$MEDICAID <- 1*(dta133$qd4a==5)
dta133$MEDICAID[dta133$qd4a %in% c(NA)] <- 0


dta133$HEALTH <- NA
dta133$HEALTH[dta133$comm==1] <- 5
dta133$HEALTH[dta133$comm==2] <- 3
dta133$HEALTH[dta133$comm==3] <- 2
dta133$HEALTH[dta133$comm==4] <- 1

#dta133$HEALTH <- NA

dta133$SAWAD <- NA
dta133$SAWADPOS <- NA
dta133$SAWADNEG <- NA
dta133$SAWADBOTH <- NA

dta133$SSTATE <- as.factor(dta133$state)

dta133$MALE <- 1*(dta133$qd1==1)

dta133$NUMBER <- 133

dta133$MONTH <- 68

dta133$MARKET <- 0
dta133$MARKET[dta133$q19==2]<-1
dta133$MARKET[dta133$q19==3
              & dta133$q20==1]<-1

dta133$SELFINSURE <- 0
dta133$SELFINSURE[dta133$qd4a==3]<-1

dta133$EMPLINSURE <- 0
dta133$EMPLINSURE[dta133$qd4a==1]<-1
dta133$EMPLINSURE[dta133$qd4a==2]<-1

dta133$PREEXIST <- NA
dta133$PREEXIST[dta133$q21==1]<-1
dta133$PREEXIST[dta133$q21=="Yes, someone in household has pre-existing condition"]<-1
dta133$PREEXIST[dta133$q21=="No, no one in household has pre-existing condition"]<-0

#sort(table(dta133$Q2CD[dta133$FAVOR==1]))/sum(sort(table(dta133$Q2CD[dta133$FAVOR==1])))

###lout133a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta133)
##summary(#lout133a)
###mf133a <- model.frame(#lout133a)

#### full data
#nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
##mf133a2 <- subsetn(dta133,select=nms)

###lout133b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta133)
##summary(#lout133b)
###mf133b <- model.frame(#lout133b)

#lout133d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta133)
#summary(#lout133d)
##fv133d <- model.frame(#lout133d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv133a2 <- subsetn(dta133,select=fvnms)

dta133$PSRAID <- dta133$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s133 <- subsetn(dta133,select=masterlist, subset=T)

##### July 2014
dta132 <- read.csv.lower("hni132.csv")

dta132$INCOME <- NA
dta132$INCOME[dta132$qd14==1] <- 10
dta132$INCOME[dta132$qd14==2] <- 25
dta132$INCOME[dta132$qd14==3] <- 35
dta132$INCOME[dta132$qd14==4] <- 45
dta132$INCOME[dta132$qd14==5] <- 62.5
dta132$INCOME[dta132$qd14==6] <- 82.5
dta132$INCOME[dta132$qd14==7] <- 95
dta132$INCOME[dta132$qd14==8] <- 200

dta132$HISP2 <- dta132$qd12
dta132$HISP <- (dta132$HISP2==1)*1

dta132$EDUC <- NA
dta132$EDUC[dta132$qd11==1] <- 6
dta132$EDUC[dta132$qd11==2] <- 10
dta132$EDUC[dta132$qd11==3] <- 12
dta132$EDUC[dta132$qd11==4] <- 13
dta132$EDUC[dta132$qd11==5] <- 14
dta132$EDUC[dta132$qd11==6] <- 16
dta132$EDUC[dta132$qd11==7] <- 17
dta132$EDUC[dta132$qd11==8] <- 19

dta132$PID <- NA
dta132$PID[dta132$qd8==2] <- 1
dta132$PID[dta132$qd8>=3 & dta132$qd8<=4] <- 2
dta132$PID[dta132$qd8==1] <- 3

dta132$PID5 <- NA
dta132$PID5[dta132$PID==1] <- 1
dta132$PID5[dta132$qd8a==1] <- 2
dta132$PID5[dta132$qd8a %in% c(9, 3, 4)] <- 3
dta132$PID5[dta132$qd8a==2] <- 4
dta132$PID5[dta132$PID==3] <- 5

dta132$REGISTERED <- NA
dta132$REGISTERED[dta132$QD9=="Yes"] <- 1
dta132$REGISTERED[dta132$QD9=="No"] <- 2

dta132$BETPER <- NA
dta132$BETPER[dta132$Q5=="Yes, have benefited"] <- 3
dta132$BETPER[dta132$Q5=="(DO NOT READ) Don't know/Refused"] <- 2
dta132$BETPER[dta132$Q5=="No, have not benefited"] <- 1

dta132$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta132$SUPPORT <- NA
#dta132$SUPPORT[dta132$Q1=="Strongly support"] <- 4
#dta132$SUPPORT[dta132$Q1=="Somewhat support"] <- 3
#dta132$SUPPORT[dta132$Q1=="Somewhat oppose"] <- 2
#dta132$SUPPORT[dta132$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta132$BLACK <- (dta132$qd13==2)*1
dta132$ASIAN <- (dta132$qd13==3)*1
dta132$OTHER <- (dta132$qd13==4)*1

dta132$AGE <- dta132$qd5
dta132$AGE[dta132$AGE==99] <- NA
dta132$MEDICARE <- (dta132$AGE > 64)*1


dta132$COVERED <- (dta132$qd4==1)*1


dta132$IDEO <- NA
dta132$IDEO[dta132$qd8b==1] <- 3
dta132$IDEO[dta132$qd8b==2] <- 2
dta132$IDEO[dta132$qd8b==3] <- 1

dta132$FAVOR <- NA
dta132$FAVOR[dta132$q3==1] <- 4
dta132$FAVOR[dta132$q3==2] <- 3
dta132$FAVOR[dta132$q3==3] <- 2
dta132$FAVOR[dta132$q3==4] <- 1

# Question Still Not Asked
dta132$SELFEMPLOY <- NA
#dta132$SELFEMPLOY[dta132$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta132$RETIRED <- 0
dta132$RETIRED[dta132$qd3==6] <- 1

dta132$MEDICARESR <- 0
dta132$MEDICARESR <- 1*(dta132$qd4a==4)
dta132$MEDICARESR[dta132$COVERED==0] <- 0

dta132$MEDICAID <- 0
dta132$MEDICAID <- 1*(dta132$qd4a==5)
dta132$MEDICAID[dta132$COVERED==0] <- 0


dta132$HEALTH <- NA
dta132$HEALTH[dta132$qd2==1] <- 5
dta132$HEALTH[dta132$qd2==2] <- 4
dta132$HEALTH[dta132$qd2==3] <- 3
dta132$HEALTH[dta132$qd2==4] <- 2
dta132$HEALTH[dta132$qd2==5] <- 1

dta132$SAWAD <- NA
dta132$SAWADPOS <- NA
dta132$SAWADNEG <- NA
dta132$SAWADBOTH <- NA

dta132$SSTATE <- dta132$state
dta132$STATE <- dta132$state

dta132$MALE <- 1*(dta132$qd1==1)

dta132$NUMBER <- 132

dta132$MONTH <- 66

dta132$MARKET <- 0
dta132$MARKET[dta132$q33==2]<-1


dta132$SELFINSURE <- 0
dta132$SELFINSURE[dta132$qd4a==3]<-1
dta132$SELFINSURE[dta132$COVERED==0] <- 0

dta132$EMPLINSURE <- 0
dta132$EMPLINSURE[dta132$qd4a==1]<-1
dta132$EMPLINSURE[dta132$qd4a==2]<-1
dta132$EMPLINSURE[dta132$COVERED==0] <- 0

dta132$PREEXIST <- NA
dta132$PREEXIST[dta132$q35=="Yes, someone in household has pre-existing condition"]<-1
dta132$PREEXIST[dta132$q35=="No, no one in household has pre-existing condition"]<-0


#sort(table(dta132$Q2CD[dta132$FAVOR==1]))/sum(sort(table(dta132$Q2CD[dta132$FAVOR==1])))

#lout132a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta132)
#summary(#lout132a)
##mf132a <- model.frame(#lout132a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf132a2 <- subsetn(dta132,select=nms)

#lout132b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta132)
#summary(#lout132b)
##mf132b <- model.frame(#lout132b)

#lout132d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta132)
#summary(#lout132d)
##fv132d <- model.frame(#lout132d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv132a2 <- subsetn(dta132,select=fvnms)

dta132$PSRAID <- dta132$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s132 <- subsetn(dta132,select=masterlist, subset=T)


##### June 2014
dta131 <- read.por.upper("hni131.por",to.data.frame=T)


dta131$INCOME <- NA
dta131$INCOME[dta131$QD14=="Less than $20,000"] <- 10
dta131$INCOME[dta131$QD14=="$20,000 to less than $30,000"] <- 25
dta131$INCOME[dta131$QD14=="$30,000 to less than $40,000"] <- 35
dta131$INCOME[dta131$QD14=="$40,000 to less than $50,000"] <- 45
dta131$INCOME[dta131$QD14=="$50,000 to less than $75,000"] <- 62.5
dta131$INCOME[dta131$QD14=="$75,000 to less than $90,000"] <- 82.5
dta131$INCOME[dta131$QD14=="$90,000 to less than $100,000"] <- 95
dta131$INCOME[dta131$QD14=="$100,000 or more"] <- 200

dta131$HISP <- (dta131$QD12=="Yes")*1

dta131$EDUC <- NA
dta131$EDUC[dta131$QD11=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta131$EDUC[dta131$QD11=="High school incomplete (Grades 9-11 or Grade 12 with no diploma)"] <- 10
dta131$EDUC[dta131$QD11=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta131$EDUC[dta131$QD11=="Some college, no degree (includes some community college)"] <- 13
dta131$EDUC[dta131$QD11=="Two year associate degree from a college or university"] <- 14
dta131$EDUC[dta131$QD11=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta131$EDUC[dta131$QD11=="Some postgraduate or professional schooling, no postgraduate degree"] <- 17
dta131$EDUC[dta131$QD11=="Postgraduate or professional degree, including master's, doctorate, medical or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta131$PID <- NA
dta131$PID[dta131$QD8=="Democrat"] <- 1
dta131$PID[dta131$QD8 %in% c("Independent","Or what?")] <- 2
dta131$PID[dta131$QD8=="Republican"] <- 3

dta131$PID5 <- NA
dta131$PID5[dta131$PID==1] <- 1
dta131$PID5[dta131$QD8A=="Democratic"] <- 2
dta131$PID5[dta131$QD8A %in% c("(DO NOT READ) Independent/don't lean to either party", "(DO NOT READ) Other party", "(DO NOT READ) Don't know/Refused")] <- 3
dta131$PID5[dta131$QD8A=="Republican"] <- 4
dta131$PID5[dta131$PID==3] <- 5

dta131$REGISTERED <- NA
dta131$REGISTERED[dta131$QD9=="Yes"] <- 1
dta131$REGISTERED[dta131$QD9=="No"] <- 2


dta131$BETPER <- NA
dta131$BETPER[dta131$Q4A=="Better off"] <- 3
dta131$BETPER[dta131$Q4A=="No difference"] <- 2
dta131$BETPER[dta131$Q4A=="(DO NOT READ) Don't know/ Refused"] <- 2
dta131$BETPER[dta131$Q4A=="Worse off"] <- 1

dta131$BETCOU <- NA
dta131$BETCOU[dta131$Q4B=="Better off"] <- 3
dta131$BETCOU[dta131$Q4B=="No difference"] <- 2
dta131$BETCOU[dta131$Q4B=="(DO NOT READ) Don't know/ Refused"] <- 2
dta131$BETCOU[dta131$Q4B=="Worse off"] <- 1

# NOTE: var replaced with FAVOR var.
dta131$SUPPORT <- NA
#dta131$SUPPORT[dta131$Q1=="Strongly support"] <- 4
#dta131$SUPPORT[dta131$Q1=="Somewhat support"] <- 3
#dta131$SUPPORT[dta131$Q1=="Somewhat oppose"] <- 2
#dta131$SUPPORT[dta131$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta131$BLACK <- (dta131$QD13=="Black or African-American")*1
dta131$ASIAN <- (dta131$QD13=="Asian")*1
dta131$OTHER <- (dta131$QD13=="Other or mixed race (SPECIFY)")*1

dta131$AGE <- dta131$QD5
dta131$AGE[dta131$AGE==99] <- NA
dta131$MEDICARE <- (dta131$AGE > 64)*1


dta131$COVERED <- (dta131$QD4=="Covered by health insurance")*1


dta131$IDEO <- NA
dta131$IDEO[dta131$QD8B=="Liberal"] <- 3
dta131$IDEO[dta131$QD8B=="Moderate"] <- 2
dta131$IDEO[dta131$QD8B=="Conservative"] <- 1

dta131$FAVOR <- NA
dta131$FAVOR[dta131$Q1=="Very favorable"] <- 4
dta131$FAVOR[dta131$Q1=="Somewhat favorable"] <- 3
dta131$FAVOR[dta131$Q1=="Somewhat unfavorable"] <- 2
dta131$FAVOR[dta131$Q1=="Very unfavorable"] <- 1

# Question Still Not Asked
dta131$SELFEMPLOY <- NA
#dta131$SELFEMPLOY[dta131$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta131$RETIRED <- 0
dta131$RETIRED[dta131$QD3=="Retired"] <- 1

dta131$MEDICARESR <- 0
dta131$MEDICARESR <- 1*(dta131$QD4A=="Medicare")
dta131$MEDICARESR[dta131$QD4A %in% c(NA)] <- 0

dta131$MEDICAID <- 0
dta131$MEDICAID <- 1*(dta131$QD4A=="Medicaid/[STATE-SPECIFIC MEDICAID NAME]")
dta131$MEDICAID[dta131$QD4A %in% c(NA)] <- 0


dta131$HEALTH <- NA
dta131$HEALTH[dta131$QD2=="Excellent"] <- 5
dta131$HEALTH[dta131$QD2=="Very good"] <- 4
dta131$HEALTH[dta131$QD2=="Good"] <- 3
dta131$HEALTH[dta131$QD2=="Only fair"] <- 2
dta131$HEALTH[dta131$QD2=="Poor"] <- 1

dta131$SAWAD <- NA
dta131$SAWADPOS <- NA
dta131$SAWADNEG <- NA
dta131$SAWADBOTH <- NA

dta131$SSTATE <- dta131$STATE

dta131$MALE <- 1*(dta131$QD1=="Male")

dta131$NUMBER <- 131

dta131$MONTH <- 65

dta131$MARKET <- 0
dta131$MARKET[dta131$Q10=="From healthcare.gov or [STATE MARKETPLACE NAME]"]<-1
dta131$MARKET[dta131$Q10=="Through an insurance agent or broker"
              & dta131$Q11=="Plan purchased from a state or federal marketplace"]<-1

dta131$SELFINSURE <- 0
dta131$SELFINSURE[dta131$QD4A=="Plan you purchased yourself"]<-1

dta131$EMPLINSURE <- 0
dta131$EMPLINSURE[dta131$QD4A=="Plan through your employer"]<-1
dta131$EMPLINSURE[dta131$QD4A=="Plan through your spouse's employer"]<-1

dta131$PREEXIST <- 0
dta131$PREEXIST[dta131$Q19=="Yes, someone in household has pre-existing condition"]<-1
dta131$PREEXIST[dta131$Q19=="No, no one in household has pre-existing condition"]<-0

#sort(table(dta131$Q2CD[dta131$FAVOR==1]))/sum(sort(table(dta131$Q2CD[dta131$FAVOR==1])))

#lout131a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta131)
#summary(#lout131a)
##mf131a <- model.frame(#lout131a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf131a2 <- subsetn(dta131,select=nms)

#lout131b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta131)
#summary(#lout131b)
##mf131b <- model.frame(#lout131b)

#lout131d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta131)
#summary(#lout131d)
##fv131d <- model.frame(#lout131d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv131a2 <- subsetn(dta131,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s131 <- subsetn(dta131,select=masterlist, subset=T)



##### May 2014
dta130 <- read.por.upper("hni130.por",to.data.frame=T)


dta130$INCOME <- NA
dta130$INCOME[dta130$QD14=="Less than $20,000"] <- 10
dta130$INCOME[dta130$QD14=="$20,000 to less than $30,000"] <- 25
dta130$INCOME[dta130$QD14=="$30,000 to less than $40,000"] <- 35
dta130$INCOME[dta130$QD14=="$40,000 to less than $50,000"] <- 45
dta130$INCOME[dta130$QD14=="$50,000 to less than $75,000"] <- 62.5
dta130$INCOME[dta130$QD14=="$75,000 to less than $90,000"] <- 82.5
dta130$INCOME[dta130$QD14=="$90,000 to less than $100,000"] <- 95
dta130$INCOME[dta130$QD14=="$100,000 or more"] <- 200

dta130$HISP <- (dta130$QD12=="Yes")*1

dta130$EDUC <- NA
dta130$EDUC[dta130$QD11=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta130$EDUC[dta130$QD11=="High school incomplete (Grades 9-11 or Grade 12 with no diploma)"] <- 10
dta130$EDUC[dta130$QD11=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta130$EDUC[dta130$QD11=="Some college, no degree (includes some community college)"] <- 13
dta130$EDUC[dta130$QD11=="Two year associate degree from a college or university"] <- 14
dta130$EDUC[dta130$QD11=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta130$EDUC[dta130$QD11=="Some postgraduate or professional schooling, no postgraduate degree"] <- 17
dta130$EDUC[dta130$QD11=="Postgraduate or professional degree, including master's, doctorate, medical or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta130$PID <- NA
dta130$PID[dta130$QD8=="Democrat"] <- 1
dta130$PID[dta130$QD8 %in% c("Independent","Or what?")] <- 2
dta130$PID[dta130$QD8=="Republican"] <- 3

dta130$PID5 <- NA
dta130$PID5[dta130$PID==1] <- 1
dta130$PID5[dta130$QD8A=="Democratic"] <- 2
dta130$PID5[dta130$QD8A %in% c("(DO NOT READ) Independent/don't lean to either party", "(DO NOT READ) Other party", "(DO NOT READ) Don't know/Refused")] <- 3
dta130$PID5[dta130$QD8A=="Republican"] <- 4
dta130$PID5[dta130$PID==3] <- 5

dta130$REGISTERED <- NA
dta130$REGISTERED[dta130$QD9=="Yes"] <- 1
dta130$REGISTERED[dta130$QD9=="No"] <- 2

dta130$BETPER <- NA
dta130$BETPER[dta130$Q6=="Yes, have benefited"] <- 3
dta130$BETPER[dta130$Q6=="(DO NOT READ) Don't know/Refused"] <- 2
dta130$BETPER[dta130$Q6=="No, have not benefited"] <- 1

dta130$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta130$SUPPORT <- NA
#dta130$SUPPORT[dta130$Q1=="Strongly support"] <- 4
#dta130$SUPPORT[dta130$Q1=="Somewhat support"] <- 3
#dta130$SUPPORT[dta130$Q1=="Somewhat oppose"] <- 2
#dta130$SUPPORT[dta130$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta130$BLACK <- (dta130$QD13=="Black or African-American")*1
dta130$ASIAN <- (dta130$QD13=="Asian")*1
dta130$OTHER <- (dta130$QD13=="Other or mixed race (SPECIFY)")*1

dta130$AGE <- dta130$QD5
dta130$AGE[dta130$AGE==99] <- NA
dta130$MEDICARE <- (dta130$AGE > 64)*1


dta130$COVERED <- (dta130$QD4=="Covered by health insurance")*1


dta130$IDEO <- NA
dta130$IDEO[dta130$QD8B=="Liberal"] <- 3
dta130$IDEO[dta130$QD8B=="Moderate"] <- 2
dta130$IDEO[dta130$QD8B=="Conservative"] <- 1

dta130$FAVOR <- NA
dta130$FAVOR[dta130$Q2=="Very favorable"] <- 4
dta130$FAVOR[dta130$Q2=="Somewhat favorable"] <- 3
dta130$FAVOR[dta130$Q2=="Somewhat unfavorable"] <- 2
dta130$FAVOR[dta130$Q2=="Very unfavorable"] <- 1

# Question Still Not Asked
dta130$SELFEMPLOY <- NA
#dta130$SELFEMPLOY[dta130$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta130$RETIRED <- 0
dta130$RETIRED[dta130$QD3=="Retired"] <- 1

dta130$MEDICARESR <- 0
dta130$MEDICARESR <- 1*(dta130$QD4A=="Medicare")
dta130$MEDICARESR[dta130$QD4A %in% c(NA)] <- 0

dta130$MEDICAID <- 0
dta130$MEDICAID <- 1*(dta130$QD4A=="Medicaid/[STATE-SPECIFIC MEDICAID NAME]")
dta130$MEDICAID[dta130$QD4A %in% c(NA)] <- 0


dta130$HEALTH <- NA
dta130$HEALTH[dta130$QD2=="Excellent"] <- 5
dta130$HEALTH[dta130$QD2=="Very good"] <- 4
dta130$HEALTH[dta130$QD2=="Good"] <- 3
dta130$HEALTH[dta130$QD2=="Only fair"] <- 2
dta130$HEALTH[dta130$QD2=="Poor"] <- 1

dta130$SAWAD <- NA
dta130$SAWADPOS <- NA
dta130$SAWADNEG <- NA
dta130$SAWADBOTH <- NA

dta130$SSTATE <- dta130$STATE

dta130$MALE <- 1*(dta130$QD1=="Male")

dta130$NUMBER <- 130

dta130$MONTH <- 64

dta130$MARKET <- 0
dta130$MARKET[dta130$Q16=="From healthcare.gov or [STATE MARKETPLACE NAME]"]<-1
dta130$MARKET[dta130$Q16=="Through an insurance agent or broker"
              & dta130$Q17=="Plan purchased from a state or federal marketplace"]<-1

dta130$SELFINSURE <- 0
dta130$SELFINSURE[dta130$QD4A=="Plan you purchased yourself"]<-1

dta130$EMPLINSURE <- 0
dta130$EMPLINSURE[dta130$QD4A=="Plan through your employer"]<-1
dta130$EMPLINSURE[dta130$QD4A=="Plan through your spouse's employer"]<-1

dta130$PREEXIST <- 0
dta130$PREEXIST[dta130$Q23=="Yes, someone in household has pre-existing condition"]<-1

#sort(table(dta130$Q2CD[dta130$FAVOR==1]))/sum(sort(table(dta130$Q2CD[dta130$FAVOR==1])))

###lout130a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta130)
##summary(#lout130a)
###mf130a <- model.frame(#lout130a)

#### full data
#nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
##mf130a2 <- subsetn(dta130,select=nms)

####lout130b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta130)
##summary(##lout130b)
###mf130b <- model.frame(##lout130b)

#lout130d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta130)
#summary(#lout130d)
##fv130d <- model.frame(#lout130d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv130a2 <- subsetn(dta130,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s130 <- subsetn(dta130,select=masterlist, subset=T)



##### April 2014
dta129 <- read.csv.lower("hni129.csv")

dta129$INCOME <- NA
dta129$INCOME[dta129$qd14==1] <- 10
dta129$INCOME[dta129$qd14==2] <- 25
dta129$INCOME[dta129$qd14==3] <- 35
dta129$INCOME[dta129$qd14==4] <- 45
dta129$INCOME[dta129$qd14==5] <- 62.5
dta129$INCOME[dta129$qd14==6] <- 82.5
dta129$INCOME[dta129$qd14==7] <- 95
dta129$INCOME[dta129$qd14==8] <- 200

dta129$HISP2 <- dta129$qd12
dta129$HISP <- (dta129$HISP2==1)*1

dta129$EDUC <- NA
dta129$EDUC[dta129$qd11==1] <- 6
dta129$EDUC[dta129$qd11==2] <- 10
dta129$EDUC[dta129$qd11==3] <- 12
dta129$EDUC[dta129$qd11==4] <- 13
dta129$EDUC[dta129$qd11==5] <- 14
dta129$EDUC[dta129$qd11==6] <- 16
dta129$EDUC[dta129$qd11==7] <- 17
dta129$EDUC[dta129$qd11==8] <- 19

dta129$PID <- NA
dta129$PID[dta129$qd8==2] <- 1
dta129$PID[dta129$qd8>=3 & dta129$qd8<=4] <- 2
dta129$PID[dta129$qd8==1] <- 3

dta129$PID5 <- NA
dta129$PID5[dta129$PID==1] <- 1
dta129$PID5[dta129$qd8a==1] <- 2
dta129$PID5[dta129$qd8a %in%  c(3, 4, 9)] <- 3
dta129$PID5[dta129$qd8a==2] <- 4
dta129$PID5[dta129$PID==3] <- 5

dta129$REGISTERED <- NA
dta129$REGISTERED[dta129$QD9=="Yes"] <- 1
dta129$REGISTERED[dta129$QD9=="No"] <- 2

dta129$BETPER <- NA
dta129$BETPER[dta129$Q4=="Yes, have benefited"] <- 3
dta129$BETPER[dta129$Q4=="(DO NOT READ) Don't know/Refused"] <- 2
dta129$BETPER[dta129$Q4=="No, have not benefited"] <- 1

dta129$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta129$SUPPORT <- NA
#dta129$SUPPORT[dta129$Q1=="Strongly support"] <- 4
#dta129$SUPPORT[dta129$Q1=="Somewhat support"] <- 3
#dta129$SUPPORT[dta129$Q1=="Somewhat oppose"] <- 2
#dta129$SUPPORT[dta129$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta129$BLACK <- (dta129$qd13==2)*1
dta129$ASIAN <- (dta129$qd13==3)*1
dta129$OTHER <- (dta129$qd13==4)*1

dta129$AGE <- dta129$qd5
dta129$AGE[dta129$AGE==99] <- NA
dta129$MEDICARE <- (dta129$AGE > 64)*1


dta129$COVERED <- (dta129$qd4==1)*1


dta129$IDEO <- NA
dta129$IDEO[dta129$qd8b==1] <- 3
dta129$IDEO[dta129$qd8b==2] <- 2
dta129$IDEO[dta129$qd8b==3] <- 1

dta129$FAVOR <- NA
dta129$FAVOR[dta129$q1==1] <- 4
dta129$FAVOR[dta129$q1==2] <- 3
dta129$FAVOR[dta129$q1==3] <- 2
dta129$FAVOR[dta129$q1==4] <- 1

# Question Still Not Asked
dta129$SELFEMPLOY <- NA
#dta129$SELFEMPLOY[dta129$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta129$RETIRED <- 0
dta129$RETIRED[dta129$qd3==6] <- 1

dta129$MEDICARESR <- 0
dta129$MEDICARESR <- 1*(dta129$qd4a==4)
dta129$MEDICARESR[dta129$COVERED==0] <- 0

dta129$MEDICAID <- 0
dta129$MEDICAID <- 1*(dta129$qd4a==5)
dta129$MEDICAID[dta129$COVERED==0] <- 0


dta129$HEALTH <- NA
dta129$HEALTH[dta129$qd2==1] <- 5
dta129$HEALTH[dta129$qd2==2] <- 4
dta129$HEALTH[dta129$qd2==3] <- 3
dta129$HEALTH[dta129$qd2==4] <- 2
dta129$HEALTH[dta129$qd2==5] <- 1

dta129$SAWAD <- NA
dta129$SAWADPOS <- NA
dta129$SAWADNEG <- NA
dta129$SAWADBOTH <- NA

dta129$SSTATE <- dta129$state
dta129$STATE <- dta129$state

dta129$MALE <- 1*(dta129$qd1==1)

dta129$NUMBER <- 129

dta129$MONTH <- 63

dta129$MARKET <- 0
dta129$MARKET[dta129$q19==2]<-1


dta129$SELFINSURE <- 0
dta129$SELFINSURE[dta129$qd4a==3]<-1
dta129$SELFINSURE[dta129$COVERED==0] <- 0

dta129$EMPLINSURE <- 0
dta129$EMPLINSURE[dta129$qd4a==1]<-1
dta129$EMPLINSURE[dta129$qd4a==2]<-1
dta129$EMPLINSURE[dta129$COVERED==0] <- 0

dta129$PREEXIST <- 0
dta129$PREEXIST[dta129$q28=="Yes, someone in household has pre-existing condition"]<-1

#sort(table(dta129$Q2CD[dta129$FAVOR==1]))/sum(sort(table(dta129$Q2CD[dta129$FAVOR==1])))

#lout129a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta129)
#summary(#lout129a)
##mf129a <- model.frame(#lout129a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf129a2 <- subsetn(dta129,select=nms)

#lout129b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta129)
#summary(#lout129b)
##mf129b <- model.frame(#lout129b)

#lout129d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta129)
#summary(#lout129d)
##fv129d <- model.frame(#lout129d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv129a2 <- subsetn(dta129,select=fvnms)

dta129$PSRAID <- dta129$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s129 <- subsetn(dta129,select=masterlist, subset=T)

##### March 2014
dta128 <- read.csv.lower("hni128.csv")

dta128$INCOME <- NA
dta128$INCOME[dta128$qd14==1] <- 10
dta128$INCOME[dta128$qd14==2] <- 25
dta128$INCOME[dta128$qd14==3] <- 35
dta128$INCOME[dta128$qd14==4] <- 45
dta128$INCOME[dta128$qd14==5] <- 62.5
dta128$INCOME[dta128$qd14==6] <- 82.5
dta128$INCOME[dta128$qd14==7] <- 95
dta128$INCOME[dta128$qd14==8] <- 200

dta128$HISP2 <- dta128$qd12
dta128$HISP <- (dta128$HISP2==1)*1

dta128$EDUC <- NA
dta128$EDUC[dta128$qd11==1] <- 6
dta128$EDUC[dta128$qd11==2] <- 10
dta128$EDUC[dta128$qd11==3] <- 12
dta128$EDUC[dta128$qd11==4] <- 13
dta128$EDUC[dta128$qd11==5] <- 14
dta128$EDUC[dta128$qd11==6] <- 16
dta128$EDUC[dta128$qd11==7] <- 17
dta128$EDUC[dta128$qd11==8] <- 19

dta128$PID <- NA
dta128$PID[dta128$qd8==2] <- 1
dta128$PID[dta128$qd8>=3 & dta128$qd8<=4] <- 2
dta128$PID[dta128$qd8==1] <- 3

dta128$PID5 <- NA
dta128$PID5[dta128$PID==1] <- 1
dta128$PID5[dta128$qd8a==1] <- 2
dta128$PID5[dta128$qd8a %in%  c(3, 4, 9)] <- 3
dta128$PID5[dta128$qd8a==2] <- 4
dta128$PID5[dta128$PID==3] <- 5

dta128$REGISTERED <- NA
dta128$REGISTERED[dta128$QD9=="Yes"] <- 1
dta128$REGISTERED[dta128$QD9=="No"] <- 2

dta128$BETPER <- NA
dta128$BETPER[dta128$Q7=="Yes, have benefited"] <- 3
dta128$BETPER[dta128$Q7=="(DO NOT READ) Don't know/Refused"] <- 2
dta128$BETPER[dta128$Q7=="No, have not benefited"] <- 1

dta128$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta128$SUPPORT <- NA
#dta128$SUPPORT[dta128$Q1=="Strongly support"] <- 4
#dta128$SUPPORT[dta128$Q1=="Somewhat support"] <- 3
#dta128$SUPPORT[dta128$Q1=="Somewhat oppose"] <- 2
#dta128$SUPPORT[dta128$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta128$BLACK <- (dta128$qd13==2)*1
dta128$ASIAN <- (dta128$qd13==3)*1
dta128$OTHER <- (dta128$qd13==4)*1

dta128$AGE <- dta128$qd5
dta128$AGE[dta128$AGE==99] <- NA
dta128$MEDICARE <- (dta128$AGE > 64)*1


dta128$COVERED <- (dta128$qd4==1)*1


dta128$IDEO <- NA
dta128$IDEO[dta128$qd8b==1] <- 3
dta128$IDEO[dta128$qd8b==2] <- 2
dta128$IDEO[dta128$qd8b==3] <- 1

dta128$FAVOR <- NA
dta128$FAVOR[dta128$q1==1] <- 4
dta128$FAVOR[dta128$q1==2] <- 3
dta128$FAVOR[dta128$q1==3] <- 2
dta128$FAVOR[dta128$q1==4] <- 1

# Question Still Not Asked
dta128$SELFEMPLOY <- NA
#dta128$SELFEMPLOY[dta128$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta128$RETIRED <- 0
dta128$RETIRED[dta128$qd3==6] <- 1

dta128$MEDICARESR <- 0
dta128$MEDICARESR <- 1*(dta128$qd4a==4)
dta128$MEDICARESR[dta128$COVERED==0] <- 0

dta128$MEDICAID <- 0
dta128$MEDICAID <- 1*(dta128$qd4a==5)
dta128$MEDICAID[dta128$COVERED==0] <- 0


dta128$HEALTH <- NA
dta128$HEALTH[dta128$qd2==1] <- 5
dta128$HEALTH[dta128$qd2==2] <- 4
dta128$HEALTH[dta128$qd2==3] <- 3
dta128$HEALTH[dta128$qd2==4] <- 2
dta128$HEALTH[dta128$qd2==5] <- 1

dta128$SAWAD <- NA
dta128$SAWADPOS <- NA
dta128$SAWADNEG <- NA
dta128$SAWADBOTH <- NA

dta128$SSTATE <- dta128$state
dta128$STATE <- dta128$state

dta128$MALE <- 1*(dta128$qd1==1)

dta128$NUMBER <- 128

dta128$MONTH <- 62

dta128$MARKET <- 0
dta128$MARKET[dta128$q27==2]<-1


dta128$SELFINSURE <- 0
dta128$SELFINSURE[dta128$qd4a==3]<-1
dta128$SELFINSURE[dta128$COVERED==0] <- 0

dta128$EMPLINSURE <- 0
dta128$EMPLINSURE[dta128$qd4a==1]<-1
dta128$EMPLINSURE[dta128$qd4a==2]<-1
dta128$EMPLINSURE[dta128$COVERED==0] <- 0

dta128$PREEXIST <- 0
dta128$PREEXIST[dta128$q32=="Yes, someone in household has pre-existing condition"]<-1

#sort(table(dta128$Q2CD[dta128$FAVOR==1]))/sum(sort(table(dta128$Q2CD[dta128$FAVOR==1])))

#lout128a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta128)
#summary(#lout128a)
##mf128a <- model.frame(#lout128a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf128a2 <- subsetn(dta128,select=nms)

#lout128b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta128)
#summary(#lout128b)
##mf128b <- model.frame(#lout128b)

#lout128d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta128)
#summary(#lout128d)
##fv128d <- model.frame(#lout128d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv128a2 <- subsetn(dta128,select=fvnms)

dta128$PSRAID <- dta128$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s128 <- subsetn(dta128,select=masterlist, subset=T)

##### February 2014
dta127 <- read.csv.lower("hni127.csv")

dta127$INCOME <- NA
dta127$INCOME[dta127$qd14==1] <- 10
dta127$INCOME[dta127$qd14==2] <- 25
dta127$INCOME[dta127$qd14==3] <- 35
dta127$INCOME[dta127$qd14==4] <- 45
dta127$INCOME[dta127$qd14==5] <- 62.5
dta127$INCOME[dta127$qd14==6] <- 82.5
dta127$INCOME[dta127$qd14==7] <- 95
dta127$INCOME[dta127$qd14==8] <- 200

dta127$HISP2 <- dta127$qd12
dta127$HISP <- (dta127$HISP2==1)*1

dta127$EDUC <- NA
dta127$EDUC[dta127$qd11==1] <- 6
dta127$EDUC[dta127$qd11==2] <- 10
dta127$EDUC[dta127$qd11==3] <- 12
dta127$EDUC[dta127$qd11==4] <- 13
dta127$EDUC[dta127$qd11==5] <- 14
dta127$EDUC[dta127$qd11==6] <- 16
dta127$EDUC[dta127$qd11==7] <- 17
dta127$EDUC[dta127$qd11==8] <- 19

dta127$PID <- NA
dta127$PID[dta127$qd8==2] <- 1
dta127$PID[dta127$qd8>=3 & dta127$qd8<=4] <- 2
dta127$PID[dta127$qd8==1] <- 3

dta127$PID5 <- NA
dta127$PID5[dta127$PID==1] <- 1
dta127$PID5[dta127$qd8a==1] <- 2
dta127$PID5[dta127$qd8a %in%  c(3, 4, 9)] <- 3
dta127$PID5[dta127$qd8a==2] <- 4
dta127$PID5[dta127$PID==3] <- 5

dta127$REGISTERED <- NA
dta127$REGISTERED[dta127$QD9=="Yes"] <- 1
dta127$REGISTERED[dta127$QD9=="No"] <- 2

dta127$BETPER <- NA
dta127$BETPER[dta127$Q5=="Yes, have benefited"] <- 3
dta127$BETPER[dta127$Q5=="(DO NOT READ) Don't know/Refused"] <- 2
dta127$BETPER[dta127$Q5=="No, have not benefited"] <- 1

dta127$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta127$SUPPORT <- NA
#dta127$SUPPORT[dta127$Q1=="Strongly support"] <- 4
#dta127$SUPPORT[dta127$Q1=="Somewhat support"] <- 3
#dta127$SUPPORT[dta127$Q1=="Somewhat oppose"] <- 2
#dta127$SUPPORT[dta127$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta127$BLACK <- (dta127$qd13==2)*1
dta127$ASIAN <- (dta127$qd13==3)*1
dta127$OTHER <- (dta127$qd13==4)*1

dta127$AGE <- dta127$qd5
dta127$AGE[dta127$AGE==99] <- NA
dta127$MEDICARE <- (dta127$AGE > 64)*1


dta127$COVERED <- (dta127$qd4==1)*1


dta127$IDEO <- NA
dta127$IDEO[dta127$qd8b==1] <- 3
dta127$IDEO[dta127$qd8b==2] <- 2
dta127$IDEO[dta127$qd8b==3] <- 1

dta127$FAVOR <- NA
dta127$FAVOR[dta127$q1==1] <- 4
dta127$FAVOR[dta127$q1==2] <- 3
dta127$FAVOR[dta127$q1==3] <- 2
dta127$FAVOR[dta127$q1==4] <- 1

# Question Still Not Asked
dta127$SELFEMPLOY <- NA
#dta127$SELFEMPLOY[dta127$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta127$RETIRED <- 0
dta127$RETIRED[dta127$qd3==6] <- 1

dta127$MEDICARESR <- 0
dta127$MEDICARESR <- 1*(dta127$qd4a==4)
dta127$MEDICARESR[dta127$COVERED==0] <- 0

dta127$MEDICAID <- 0
dta127$MEDICAID <- 1*(dta127$qd4a==5)
dta127$MEDICAID[dta127$COVERED==0] <- 0


dta127$HEALTH <- NA
dta127$HEALTH[dta127$qd2==1] <- 5
dta127$HEALTH[dta127$qd2==2] <- 4
dta127$HEALTH[dta127$qd2==3] <- 3
dta127$HEALTH[dta127$qd2==4] <- 2
dta127$HEALTH[dta127$qd2==5] <- 1

dta127$SAWAD <- NA
dta127$SAWADPOS <- NA
dta127$SAWADNEG <- NA
dta127$SAWADBOTH <- NA

dta127$SSTATE <- dta127$state
dta127$STATE <- dta127$state

dta127$MALE <- 1*(dta127$qd1==1)

dta127$NUMBER <- 127

dta127$MONTH <- 61

dta127$MARKET <- 0
dta127$MARKET[dta127$q26==2]<-1


dta127$SELFINSURE <- 0
dta127$SELFINSURE[dta127$qd4a==3]<-1
dta127$SELFINSURE[dta127$COVERED==0] <- 0

dta127$EMPLINSURE <- 0
dta127$EMPLINSURE[dta127$qd4a==1]<-1
dta127$EMPLINSURE[dta127$qd4a==2]<-1
dta127$EMPLIKSURE[dta127$COVERED==0] <- 0

dta127$PREEXIST <- NA

#sort(table(dta127$Q2CD[dta127$FAVOR==1]))/sum(sort(table(dta127$Q2CD[dta127$FAVOR==1])))

#lout127a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta127)
#summary(#lout127a)
##mf127a <- model.frame(#lout127a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf127a2 <- subsetn(dta127,select=nms)

#lout127b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta127)
#summary(#lout127b)
##mf127b <- model.frame(#lout127b)

#lout127d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta127)
#summary(#lout127d)
##fv127d <- model.frame(#lout127d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv127a2 <- subsetn(dta127,select=fvnms)

dta127$PSRAID <- dta127$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s127 <- subsetn(dta127,select=masterlist, subset=T)

##### January 2014
dta126 <- read.csv.lower("hni126.csv")

dta126$INCOME <- NA
dta126$INCOME[dta126$qd14==1] <- 10
dta126$INCOME[dta126$qd14==2] <- 25
dta126$INCOME[dta126$qd14==3] <- 35
dta126$INCOME[dta126$qd14==4] <- 45
dta126$INCOME[dta126$qd14==5] <- 62.5
dta126$INCOME[dta126$qd14==6] <- 82.5
dta126$INCOME[dta126$qd14==7] <- 95
dta126$INCOME[dta126$qd14==8] <- 200

dta126$HISP2 <- dta126$qd12
dta126$HISP <- (dta126$HISP2==1)*1

dta126$EDUC <- NA
dta126$EDUC[dta126$qd11==1] <- 6
dta126$EDUC[dta126$qd11==2] <- 10
dta126$EDUC[dta126$qd11==3] <- 12
dta126$EDUC[dta126$qd11==4] <- 13
dta126$EDUC[dta126$qd11==5] <- 14
dta126$EDUC[dta126$qd11==6] <- 16
dta126$EDUC[dta126$qd11==7] <- 17
dta126$EDUC[dta126$qd11==8] <- 19

dta126$PID <- NA
dta126$PID[dta126$qd8==2] <- 1
dta126$PID[dta126$qd8>=3 & dta126$qd8<=4] <- 2
dta126$PID[dta126$qd8==1] <- 3

dta126$PID5 <- NA
dta126$PID5[dta126$PID==1] <- 1
dta126$PID5[dta126$qd8a==1] <- 2
dta126$PID5[dta126$qd8a %in%  c(3, 4, 9)] <- 3
dta126$PID5[dta126$qd8a==2] <- 4
dta126$PID5[dta126$PID==3] <- 5

dta126$REGISTERED <- NA
dta126$REGISTERED[dta126$QD9=="Yes"] <- 1
dta126$REGISTERED[dta126$QD9=="No"] <- 2

dta126$BETPER <- NA
dta126$BETPER[dta126$Q3A=="Better off"] <- 3
dta126$BETPER[dta126$Q3A=="No difference"] <- 2
dta126$BETPER[dta126$Q3A=="(DO NOT READ) Don't know/Refused"] <- 2
dta126$BETPER[dta126$Q3A=="Worse off"] <- 1

dta126$BETCOU <- NA
dta126$BETCOU[dta126$Q3B=="Better off"] <- 3
dta126$BETCOU[dta126$Q3B=="No difference"] <- 2
dta126$BETCOU[dta126$Q3B=="(DO NOT READ) Don't know/Refused"] <- 2
dta126$BETCOU[dta126$Q3B=="Worse off"] <- 1

# NOTE: var replaced with FAVOR var.
dta126$SUPPORT <- NA
#dta126$SUPPORT[dta126$Q1=="Strongly support"] <- 4
#dta126$SUPPORT[dta126$Q1=="Somewhat support"] <- 3
#dta126$SUPPORT[dta126$Q1=="Somewhat oppose"] <- 2
#dta126$SUPPORT[dta126$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta126$BLACK <- (dta126$qd13==2)*1
dta126$ASIAN <- (dta126$qd13==3)*1
dta126$OTHER <- (dta126$qd13==4)*1

dta126$AGE <- dta126$qd5
dta126$AGE[dta126$AGE==99] <- NA
dta126$MEDICARE <- (dta126$AGE > 64)*1


dta126$COVERED <- (dta126$qd4==1)*1


dta126$IDEO <- NA
dta126$IDEO[dta126$qd8b==1] <- 3
dta126$IDEO[dta126$qd8b==2] <- 2
dta126$IDEO[dta126$qd8b==3] <- 1

dta126$FAVOR <- NA
dta126$FAVOR[dta126$q1==1] <- 4
dta126$FAVOR[dta126$q1==2] <- 3
dta126$FAVOR[dta126$q1==3] <- 2
dta126$FAVOR[dta126$q1==4] <- 1

# Question Still Not Asked
dta126$SELFEMPLOY <- NA
#dta126$SELFEMPLOY[dta126$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta126$RETIRED <- 0
dta126$RETIRED[dta126$qd3==6] <- 1

dta126$MEDICARESR <- 0
dta126$MEDICARESR <- 1*(dta126$qd4a==4)
dta126$MEDICARESR[dta126$COVERED==0] <- 0

dta126$MEDICAID <- 0
dta126$MEDICAID <- 1*(dta126$qd4a==5)
dta126$MEDICAID[dta126$COVERED==0] <- 0


dta126$HEALTH <- NA
dta126$HEALTH[dta126$qd2==1] <- 5
dta126$HEALTH[dta126$qd2==2] <- 4
dta126$HEALTH[dta126$qd2==3] <- 3
dta126$HEALTH[dta126$qd2==4] <- 2
dta126$HEALTH[dta126$qd2==5] <- 1

dta126$SAWAD <- NA
dta126$SAWADPOS <- NA
dta126$SAWADNEG <- NA
dta126$SAWADBOTH <- NA

dta126$SSTATE <- dta126$state
dta126$STATE <- dta126$state

dta126$MALE <- 1*(dta126$qd1==1)

dta126$NUMBER <- 126

dta126$MONTH <- 60

dta126$MARKET <- NA

dta126$SELFINSURE <- 0
dta126$SELFINSURE[dta126$qd4a==3]<-1
dta126$SELFINSURE[dta126$COVERED==0] <- 0

dta126$EMPLINSURE <- 0
dta126$EMPLINSURE[dta126$qd4a==1]<-1
dta126$EMPLINSURE[dta126$qd4a==2]<-1
dta126$EMPLINSURE[dta126$COVERED==0] <- 0

dta126$PREEXIST <- 0
dta126$PREEXIST[dta126$q35=="Yes, someone in household has pre-existing condition"]<-1

#sort(table(dta126$Q2CD[dta126$FAVOR==1]))/sum(sort(table(dta126$Q2CD[dta126$FAVOR==1])))

#lout126a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta126)
#summary(#lout126a)
##mf126a <- model.frame(#lout126a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf126a2 <- subsetn(dta126,select=nms)

#lout126b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta126)
#summary(#lout126b)
##mf126b <- model.frame(#lout126b)

#lout126d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta126)
#summary(#lout126d)
##fv126d <- model.frame(#lout126d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv126a2 <- subsetn(dta126,select=fvnms)

dta126$PSRAID <- dta126$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s126 <- subsetn(dta126,select=masterlist, subset=T)


##### December 2013
dta125 <- read.csv.lower("hni125.csv")

dta125$INCOME <- NA
dta125$INCOME[dta125$qd14==1] <- 10
dta125$INCOME[dta125$qd14==2] <- 25
dta125$INCOME[dta125$qd14==3] <- 35
dta125$INCOME[dta125$qd14==4] <- 45
dta125$INCOME[dta125$qd14==5] <- 62.5
dta125$INCOME[dta125$qd14==6] <- 82.5
dta125$INCOME[dta125$qd14==7] <- 95
dta125$INCOME[dta125$qd14==8] <- 200

dta125$HISP2 <- dta125$qd12
dta125$HISP <- (dta125$HISP2==1)*1

dta125$EDUC <- NA
dta125$EDUC[dta125$qd11==1] <- 6
dta125$EDUC[dta125$qd11==2] <- 10
dta125$EDUC[dta125$qd11==3] <- 12
dta125$EDUC[dta125$qd11==4] <- 13
dta125$EDUC[dta125$qd11==5] <- 14
dta125$EDUC[dta125$qd11==6] <- 16
dta125$EDUC[dta125$qd11==7] <- 17
dta125$EDUC[dta125$qd11==8] <- 19

dta125$PID <- NA
dta125$PID[dta125$qd8==2] <- 1
dta125$PID[dta125$qd8>=3 & dta125$qd8<=4] <- 2
dta125$PID[dta125$qd8==1] <- 3

dta125$PID5 <- NA
dta125$PID5[dta125$PID==1] <- 1
dta125$PID5[dta125$qd8a==1] <- 2
dta125$PID5[dta125$qd8a %in%  c(3, 4, 9)] <- 3
dta125$PID5[dta125$qd8a==2] <- 4
dta125$PID5[dta125$PID==3] <- 5

dta125$REGISTERED <- NA
dta125$REGISTERED[dta125$QD9=="Yes"] <- 1
dta125$REGISTERED[dta125$QD9=="No"] <- 2


dta125$BETPER <- NA
dta125$BETPER[dta125$Q4A=="Better off"] <- 3
dta125$BETPER[dta125$Q4A=="No difference"] <- 2
dta125$BETPER[dta125$Q4A=="(DO NOT READ) Don't know/Refused"] <- 2
dta125$BETPER[dta125$Q4A=="Worse off"] <- 1

dta125$BETCOU <- NA
dta125$BETCOU[dta125$Q4B=="Better off"] <- 3
dta125$BETCOU[dta125$Q4B=="No difference"] <- 2
dta125$BETCOU[dta125$Q4B=="(DO NOT READ) Don't know/Refused"] <- 2
dta125$BETCOU[dta125$Q4B=="Worse off"] <- 1

# NOTE: var replaced with FAVOR var.
dta125$SUPPORT <- NA
#dta125$SUPPORT[dta125$Q1=="Strongly support"] <- 4
#dta125$SUPPORT[dta125$Q1=="Somewhat support"] <- 3
#dta125$SUPPORT[dta125$Q1=="Somewhat oppose"] <- 2
#dta125$SUPPORT[dta125$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta125$BLACK <- (dta125$qd13==2)*1
dta125$ASIAN <- (dta125$qd13==3)*1
dta125$OTHER <- (dta125$qd13==4)*1

dta125$AGE <- dta125$qd5
dta125$AGE[dta125$AGE==99] <- NA
dta125$MEDICARE <- (dta125$AGE > 64)*1


dta125$COVERED <- (dta125$qd4==1)*1


dta125$IDEO <- NA
dta125$IDEO[dta125$qd8b==1] <- 3
dta125$IDEO[dta125$qd8b==2] <- 2
dta125$IDEO[dta125$qd8b==3] <- 1

dta125$FAVOR <- NA
dta125$FAVOR[dta125$q1==1] <- 4
dta125$FAVOR[dta125$q1==2] <- 3
dta125$FAVOR[dta125$q1==3] <- 2
dta125$FAVOR[dta125$q1==4] <- 1

# Question Still Not Asked
dta125$SELFEMPLOY <- NA
#dta125$SELFEMPLOY[dta125$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta125$RETIRED <- 0
dta125$RETIRED[dta125$qd3==6] <- 1

dta125$MEDICARESR <- 0
dta125$MEDICARESR <- 1*(dta125$qd4a==4)
dta125$MEDICARESR[dta125$COVERED==0] <- 0

dta125$MEDICAID <- 0
dta125$MEDICAID <- 1*(dta125$qd4a==5)
dta125$MEDICAID[dta125$COVERED==0] <- 0

dta125$HEALTH <- NA
dta125$HEALTH[dta125$qd2==1] <- 5
dta125$HEALTH[dta125$qd2==2] <- 4
dta125$HEALTH[dta125$qd2==3] <- 3
dta125$HEALTH[dta125$qd2==4] <- 2
dta125$HEALTH[dta125$qd2==5] <- 1

dta125$SAWAD <- NA
dta125$SAWADPOS <- NA
dta125$SAWADNEG <- NA
dta125$SAWADBOTH <- NA

dta125$SSTATE <- dta125$state
dta125$STATE <- dta125$state

dta125$MALE <- 1*(dta125$qd1==1)

dta125$NUMBER <- 125

dta125$MONTH <- 59

dta125$MARKET <- NA

dta125$SELFINSURE <- 0
dta125$SELFINSURE[dta125$qd4a==3]<-1
dta125$SELFINSURE[dta125$COVERED==0] <- 0

dta125$EMPLINSURE <- 0
dta125$EMPLINSURE[dta125$qd4a==1]<-1
dta125$EMPLINSURE[dta125$qd4a==2]<-1
dta125$EMPLINSURE[dta125$COVERED==0] <- 0

dta125$PREEXIST <- 0
dta125$PREEXIST[dta125$q25=="Yes, someone in household has pre-existing condition"]<-1


#sort(table(dta125$Q2CD[dta125$FAVOR==1]))/sum(sort(table(dta125$Q2CD[dta125$FAVOR==1])))

#lout125a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta125)
#summary(#lout125a)
##mf125a <- model.frame(#lout125a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf125a2 <- subsetn(dta125,select=nms)

#lout125b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta125)
#summary(#lout125b)
##mf125b <- model.frame(#lout125b)

#lout125d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta125)
#summary(#lout125d)
##fv125d <- model.frame(#lout125d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv125a2 <- subsetn(dta125,select=fvnms)

dta125$PSRAID <- dta125$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s125 <- subsetn(dta125,select=masterlist, subset=T)


##### November 2013
dta124 <- read.por.upper("hni124.por",to.data.frame=T)


dta124$INCOME <- NA
dta124$INCOME[dta124$QD14=="Less than $20,000"] <- 10
dta124$INCOME[dta124$QD14=="$20,000 to less than $30,000"] <- 25
dta124$INCOME[dta124$QD14=="$30,000 to less than $40,000"] <- 35
dta124$INCOME[dta124$QD14=="$40,000 to less than $50,000"] <- 45
dta124$INCOME[dta124$QD14=="$50,000 to less than $75,000"] <- 62.5
dta124$INCOME[dta124$QD14=="$75,000 to less than $90,000"] <- 82.5
dta124$INCOME[dta124$QD14=="$90,000 to less than $100,000"] <- 95
dta124$INCOME[dta124$QD14=="$100,000 or more"] <- 200

dta124$HISP <- (dta124$D12=="Yes")*1

dta124$EDUC <- NA
dta124$EDUC[dta124$D11=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta124$EDUC[dta124$D11=="High school incomplete (Grades 9-11 or Grade 12 with no diploma)"] <- 10
dta124$EDUC[dta124$D11=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta124$EDUC[dta124$D11=="Some college, no degree (includes some community college)"] <- 13
dta124$EDUC[dta124$D11=="Two year associate degree from a college or university"] <- 14
dta124$EDUC[dta124$D11=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta124$EDUC[dta124$D11=="Some postgraduate or professional schooling, no postgraduate degree"] <- 17
dta124$EDUC[dta124$D11=="Postgraduate or professional degree, including master's, doctorate, medical or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta124$PID <- NA
dta124$PID[dta124$QD8=="Democrat"] <- 1
dta124$PID[dta124$QD8 %in% c("Independent","Or what?")] <- 2
dta124$PID[dta124$QD8=="Republican"] <- 3

dta124$PID5 <- NA
dta124$PID5[dta124$PID==1] <- 1
dta124$PID5[dta124$QD8A=="Democratic"] <- 2
dta124$PID5[dta124$QD8A %in% c("(DO NOT READ) Independent/don't lean to either party", "(DO NOT READ) Other party", "(DO NOT READ) Don't know/Refused")] <- 3
dta124$PID5[dta124$QD8A=="Republican"] <- 4
dta124$PID5[dta124$PID==3] <- 5

dta124$REGISTERED <- NA
dta124$REGISTERED[dta124$QD9=="Yes"] <- 1
dta124$REGISTERED[dta124$QD9=="No"] <- 2


dta124$BETPER <- NA
dta124$BETPER[dta124$Q2A=="Better off"] <- 3
dta124$BETPER[dta124$Q2A=="No difference"] <- 2
dta124$BETPER[dta124$Q2A=="(DO NOT READ) Don't know/Refused"] <- 2
dta124$BETPER[dta124$Q2A=="Worse off"] <- 1

dta124$BETCOU <- NA
dta124$BETCOU[dta124$Q2B=="Better off"] <- 3
dta124$BETCOU[dta124$Q2B=="No difference"] <- 2
dta124$BETCOU[dta124$Q2B=="(DO NOT READ) Don't know/Refused"] <- 2
dta124$BETCOU[dta124$Q2B=="Worse off"] <- 1

# NOTE: var replaced with FAVOR var.
dta124$SUPPORT <- NA
#dta124$SUPPORT[dta124$Q1=="Strongly support"] <- 4
#dta124$SUPPORT[dta124$Q1=="Somewhat support"] <- 3
#dta124$SUPPORT[dta124$Q1=="Somewhat oppose"] <- 2
#dta124$SUPPORT[dta124$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta124$BLACK <- (dta124$D13=="Black or African-American")*1
dta124$ASIAN <- (dta124$D13=="Asian")*1
dta124$OTHER <- (dta124$D13=="Other or mixed race (SPECIFY)")*1

dta124$AGE <- dta124$QD5
dta124$AGE[dta124$AGE==99] <- NA
dta124$MEDICARE <- (dta124$AGE > 64)*1


dta124$COVERED <- (dta124$QD4=="Covered by health insurance")*1


dta124$IDEO <- NA
dta124$IDEO[dta124$QD8B=="Liberal"] <- 3
dta124$IDEO[dta124$QD8B=="Moderate"] <- 2
dta124$IDEO[dta124$QD8B=="Conservative"] <- 1

dta124$FAVOR <- NA
dta124$FAVOR[dta124$Q1=="Very favorable"] <- 4
dta124$FAVOR[dta124$Q1=="Somewhat favorable"] <- 3
dta124$FAVOR[dta124$Q1=="Somewhat unfavorable"] <- 2
dta124$FAVOR[dta124$Q1=="Very unfavorable"] <- 1

# Question Still Not Asked
dta124$SELFEMPLOY <- NA
#dta124$SELFEMPLOY[dta124$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta124$RETIRED <- 0
dta124$RETIRED[dta124$QD3=="Retired"] <- 1

dta124$MEDICARESR <- 0
dta124$MEDICARESR <- 1*(dta124$QD4A=="Medicare")
dta124$MEDICARESR[dta124$QD4A %in% c(NA)] <- 0

dta124$MEDICAID <- 0
dta124$MEDICAID <- 1*(dta124$QD4A=="Medicaid/Medi-CAL")
dta124$MEDICAID[dta124$QD4A %in% c(NA)] <- 0


dta124$HEALTH <- NA
dta124$HEALTH[dta124$QD2=="Excellent"] <- 5
dta124$HEALTH[dta124$QD2=="Very good"] <- 4
dta124$HEALTH[dta124$QD2=="Good"] <- 3
dta124$HEALTH[dta124$QD2=="Only fair"] <- 2
dta124$HEALTH[dta124$QD2=="Poor"] <- 1

dta124$SAWAD <- NA
dta124$SAWADPOS <- NA
dta124$SAWADNEG <- NA
dta124$SAWADBOTH <- NA

dta124$SSTATE <- dta124$STATE

dta124$MALE <- 1*(dta124$QD1=="Male")

dta124$NUMBER <- 124

dta124$MARKET <- NA

dta124$MONTH <- 58

dta124$SELFINSURE <- 0
dta124$SELFINSURE[dta124$QD4A=="Plan you purchased yourself"]<-1

dta124$EMPLINSURE <- 0
dta124$EMPLINSURE[dta124$QD4A=="Plan through your employer"]<-1
dta124$EMPLINSURE[dta124$QD4A=="Plan through your spouse's employer"]<-1

dta124$PREEXIST <- 0
dta124$PREEXIST[dta124$Q14=="Yes, someone in household has pre-existing condition"]<-1

#sort(table(dta124$Q2CD[dta124$FAVOR==1]))/sum(sort(table(dta124$Q2CD[dta124$FAVOR==1])))

#lout124a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta124)
#summary(#lout124a)
##mf124a <- model.frame(#lout124a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf124a2 <- subsetn(dta124,select=nms)

#lout124b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta124)
#summary(#lout124b)
##mf124b <- model.frame(#lout124b)

#lout124d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta124)
#summary(#lout124d)
##fv124d <- model.frame(#lout124d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv124a2 <- subsetn(dta124,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s124 <- subsetn(dta124,select=masterlist, subset=T)


##### October 2013
dta123 <- read.csv.lower("hni123.csv")

dta123$INCOME <- NA
dta123$INCOME[dta123$qd14==1] <- 10
dta123$INCOME[dta123$qd14==2] <- 25
dta123$INCOME[dta123$qd14==3] <- 35
dta123$INCOME[dta123$qd14==4] <- 45
dta123$INCOME[dta123$qd14==5] <- 62.5
dta123$INCOME[dta123$qd14==6] <- 82.5
dta123$INCOME[dta123$qd14==7] <- 95
dta123$INCOME[dta123$qd14==8] <- 200

dta123$HISP2 <- dta123$qd12
dta123$HISP <- (dta123$HISP2==1)*1

dta123$EDUC <- NA
dta123$EDUC[dta123$qd11==1] <- 6
dta123$EDUC[dta123$qd11==2] <- 10
dta123$EDUC[dta123$qd11==3] <- 12
dta123$EDUC[dta123$qd11==4] <- 13
dta123$EDUC[dta123$qd11==5] <- 14
dta123$EDUC[dta123$qd11==6] <- 16
dta123$EDUC[dta123$qd11==7] <- 17
dta123$EDUC[dta123$qd11==8] <- 19

dta123$PID <- NA
dta123$PID[dta123$qd8==2] <- 1
dta123$PID[dta123$qd8>=3 & dta123$qd8<=4] <- 2
dta123$PID[dta123$qd8==1] <- 3

dta123$PID5 <- NA
dta123$PID5[dta123$PID==1] <- 1
dta123$PID5[dta123$qd8a==1] <- 2
dta123$PID5[dta123$qd8a %in%  c(3, 4, 9)] <- 3
dta123$PID5[dta123$qd8a==2] <- 4
dta123$PID5[dta123$PID==3] <- 5

dta123$REGISTERED <- NA
dta123$REGISTERED[dta123$QD9=="Yes"] <- 1
dta123$REGISTERED[dta123$QD9=="No"] <- 2

dta123$BETPER <- NA
dta123$BETPER[dta123$Q5A=="Better off"] <- 3
dta123$BETPER[dta123$Q5A=="No difference"] <- 2
dta123$BETPER[dta123$Q5A=="(DO NOT READ) Don't know/Refused"] <- 2
dta123$BETPER[dta123$Q5A=="Worse off"] <- 1

dta123$BETCOU <- NA
dta123$BETCOU[dta123$Q5B=="Better off"] <- 3
dta123$BETCOU[dta123$Q5B=="No difference"] <- 2
dta123$BETCOU[dta123$Q5B=="(DO NOT READ) Don't know/Refused"] <- 2
dta123$BETCOU[dta123$Q5B=="Worse off"] <- 1

# NOTE: var replaced with FAVOR var.
dta123$SUPPORT <- NA
#dta123$SUPPORT[dta123$Q1=="Strongly support"] <- 4
#dta123$SUPPORT[dta123$Q1=="Somewhat support"] <- 3
#dta123$SUPPORT[dta123$Q1=="Somewhat oppose"] <- 2
#dta123$SUPPORT[dta123$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta123$BLACK <- (dta123$qd13==2)*1
dta123$ASIAN <- (dta123$qd13==3)*1
dta123$OTHER <- (dta123$qd13==4)*1

dta123$AGE <- dta123$qd5
dta123$AGE[dta123$AGE==99] <- NA
dta123$MEDICARE <- (dta123$AGE > 64)*1

dta123$COVERED <- (dta123$qd4==1)*1

dta123$IDEO <- NA
dta123$IDEO[dta123$qd8b==1] <- 3
dta123$IDEO[dta123$qd8b==2] <- 2
dta123$IDEO[dta123$qd8b==3] <- 1

dta123$FAVOR <- NA
dta123$FAVOR[dta123$q1==1] <- 4
dta123$FAVOR[dta123$q1==2] <- 3
dta123$FAVOR[dta123$q1==3] <- 2
dta123$FAVOR[dta123$q1==4] <- 1

# Question Still Not Asked
dta123$SELFEMPLOY <- NA
#dta123$SELFEMPLOY[dta123$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta123$RETIRED <- 0
dta123$RETIRED[dta123$qd3==6] <- 1

dta123$MEDICARESR <- 0
dta123$MEDICARESR <- 1*(dta123$qd4a==4)
dta123$MEDICARESR[dta123$COVERED==0] <- 0

dta123$MEDICAID <- 0
dta123$MEDICAID <- 1*(dta123$qd4a==5)
dta123$MEDICAID[dta123$COVERED==0] <- 0

dta123$HEALTH <- NA
dta123$HEALTH[dta123$qd2==1] <- 5
dta123$HEALTH[dta123$qd2==2] <- 4
dta123$HEALTH[dta123$qd2==3] <- 3
dta123$HEALTH[dta123$qd2==4] <- 2
dta123$HEALTH[dta123$qd2==5] <- 1

dta123$SAWAD <- NA
dta123$SAWADPOS <- NA
dta123$SAWADNEG <- NA
dta123$SAWADBOTH <- NA

dta123$SSTATE <- dta123$state
dta123$STATE <- dta123$state

dta123$MALE <- 1*(dta123$qd1==1)

dta123$NUMBER <- 123

dta123$MONTH <- 57

dta123$MARKET <- NA

dta123$SELFINSURE <- 0
dta123$SELFINSURE[dta123$qd4a==3]<-1
dta123$SELFINSURE[dta123$COVERED==0] <- 0

dta123$EMPLINSURE <- 0
dta123$EMPLINSURE[dta123$qd4a==1]<-1
dta123$EMPLINSURE[dta123$qd4a==2]<-1
dta123$EMPLINSURE[dta123$COVERED==0] <- 0

dta123$PREEXIST <- 0
dta123$PREEXIST[dta123$q16=="Yes, someone in household has pre-existing condition"]<-1


#sort(table(dta123$Q2CD[dta123$FAVOR==1]))/sum(sort(table(dta123$Q2CD[dta123$FAVOR==1])))

#lout123a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta123)
#summary(#lout123a)
##mf123a <- model.frame(#lout123a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf123a2 <- subsetn(dta123,select=nms)

#lout123b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta123)
#summary(#lout123b)
##mf123b <- model.frame(#lout123b)

#lout123d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta123)
#summary(#lout123d)
##fv123d <- model.frame(#lout123d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv123a2 <- subsetn(dta123,select=fvnms)

dta123$PSRAID <- dta123$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s123 <- subsetn(dta123,select=masterlist, subset=T)

##### September 2013
dta122 <- read.por.upper("hni122.por",to.data.frame=T)


dta122$INCOME <- NA
dta122$INCOME[dta122$QD14=="Less than $20,000"] <- 10
dta122$INCOME[dta122$QD14=="$20,000 to less than $30,000"] <- 25
dta122$INCOME[dta122$QD14=="$30,000 to less than $40,000"] <- 35
dta122$INCOME[dta122$QD14=="$40,000 to less than $50,000"] <- 45
dta122$INCOME[dta122$QD14=="$50,000 to less than $75,000"] <- 62.5
dta122$INCOME[dta122$QD14=="$75,000 to less than $90,000"] <- 82.5
dta122$INCOME[dta122$QD14=="$90,000 to less than $100,000"] <- 95
dta122$INCOME[dta122$QD14=="$100,000 or more"] <- 200

dta122$HISP <- (dta122$QD12=="Yes")*1

dta122$EDUC <- NA
dta122$EDUC[dta122$QD11=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta122$EDUC[dta122$QD11=="High school incomplete (Grades 9-11 or Grade 12 with NO diploma)"] <- 10
dta122$EDUC[dta122$QD11=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta122$EDUC[dta122$QD11=="Some college, no degree (includes some community college)"] <- 13
dta122$EDUC[dta122$QD11=="Two year associate degree from a college or university"] <- 14
dta122$EDUC[dta122$QD11=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta122$EDUC[dta122$QD11=="Some postgraduate or professional schooling, no postgraduate degree"] <- 17
dta122$EDUC[dta122$QD11=="Postgraduate or professional degree, including master's, doctorate, medical or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta122$PID <- NA
dta122$PID[dta122$QD8=="Democrat"] <- 1
dta122$PID[dta122$QD8 %in% c("Independent","Or what?")] <- 2
dta122$PID[dta122$QD8=="Republican"] <- 3

dta122$PID5 <- NA
dta122$PID5[dta122$PID==1] <- 1
dta122$PID5[dta122$QD8A=="Democratic"] <- 2
dta122$PID5[dta122$QD8A %in% c("Independent/don't lean to either party (VOL.)", "Other party (VOL.)", "(DO NOT READ) Don't know/Refused")] <- 3
dta122$PID5[dta122$QD8A=="Republican"] <- 4
dta122$PID5[dta122$PID==3] <- 5

dta122$REGISTERED <- NA
dta122$REGISTERED[dta122$QD9=="Yes"] <- 1
dta122$REGISTERED[dta122$QD9=="No"] <- 2


dta122$BETPER <- NA
dta122$BETPER[dta122$Q4A=="Better off"] <- 3
dta122$BETPER[dta122$Q4A=="No difference"] <- 2
dta122$BETPER[dta122$Q4A=="(DO NOT READ) Don't know/Refused"] <- 2
dta122$BETPER[dta122$Q4A=="Worse off"] <- 1

dta122$BETCOU <- NA
dta122$BETCOU[dta122$Q4B=="Better off"] <- 3
dta122$BETCOU[dta122$Q4B=="No difference"] <- 2
dta122$BETCOU[dta122$Q4B=="(DO NOT READ) Don't know/Refused"] <- 2
dta122$BETCOU[dta122$Q4B=="Worse off"] <- 1

# NOTE: var replaced with FAVOR var.
dta122$SUPPORT <- NA
#dta122$SUPPORT[dta122$Q1=="Strongly support"] <- 4
#dta122$SUPPORT[dta122$Q1=="Somewhat support"] <- 3
#dta122$SUPPORT[dta122$Q1=="Somewhat oppose"] <- 2
#dta122$SUPPORT[dta122$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta122$BLACK <- (dta122$QD13=="Black or African-American")*1
dta122$ASIAN <- (dta122$QD13=="Asian")*1
dta122$OTHER <- (dta122$QD13=="Other or mixed race (SPECIFY)")*1

dta122$AGE <- dta122$QD5
dta122$AGE[dta122$AGE==99] <- NA
dta122$MEDICARE <- (dta122$AGE > 64)*1


dta122$COVERED <- (dta122$QD4=="Covered by health insurance")*1


dta122$IDEO <- NA
dta122$IDEO[dta122$QD8B=="Liberal"] <- 3
dta122$IDEO[dta122$QD8B=="Moderate"] <- 2
dta122$IDEO[dta122$QD8B=="Conservative"] <- 1

dta122$FAVOR <- NA
dta122$FAVOR[dta122$Q1=="Very favorable"] <- 4
dta122$FAVOR[dta122$Q1=="Somewhat favorable"] <- 3
dta122$FAVOR[dta122$Q1=="Somewhat unfavorable"] <- 2
dta122$FAVOR[dta122$Q1=="Very unfavorable"] <- 1

# Question Still Not Asked
dta122$SELFEMPLOY <- NA
#dta122$SELFEMPLOY[dta122$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta122$RETIRED <- 0
dta122$RETIRED[dta122$QD3=="Retired"] <- 1

dta122$MEDICARESR <- 0
dta122$MEDICARESR <- 1*(dta122$QD4A=="Medicare")
dta122$MEDICARESR[dta122$QD4A %in% c(NA)] <- 0

dta122$MEDICAID <- 0
dta122$MEDICAID <- 1*(dta122$QD4A=="Medicaid/Medi-CAL")
dta122$MEDICAID[dta122$QD4A %in% c(NA)] <- 0


dta122$HEALTH <- NA
dta122$HEALTH[dta122$QD2=="Excellent"] <- 5
dta122$HEALTH[dta122$QD2=="Very good"] <- 4
dta122$HEALTH[dta122$QD2=="Good"] <- 3
dta122$HEALTH[dta122$QD2=="Only fair"] <- 2
dta122$HEALTH[dta122$QD2=="Poor"] <- 1

dta122$SAWAD <- NA
dta122$SAWADPOS <- NA
dta122$SAWADNEG <- NA
dta122$SAWADBOTH <- NA

dta122$SSTATE <- dta122$STATE

dta122$MALE <- 1*(dta122$QD1=="Male")

dta122$NUMBER <- 122

dta122$MARKET <- NA

dta122$MONTH <- 56

dta122$SELFINSURE <- 0
dta122$SELFINSURE[dta122$QD4A=="Plan you purchased yourself"]<-1

dta122$EMPLINSURE <- 0
dta122$EMPLINSURE[dta122$QD4A=="Plan through your employer"]<-1
dta122$EMPLINSURE[dta122$QD4A=="Plan through your spouse's employer"]<-1

dta122$PREEXIST <- 0
dta122$PREEXIST[dta122$Q26=="Yes, someone in household has pre-existing condition"]<-1

#sort(table(dta122$Q2CD[dta122$FAVOR==1]))/sum(sort(table(dta122$Q2CD[dta122$FAVOR==1])))

#lout122a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta122)
#summary(#lout122a)
##mf122a <- model.frame(#lout122a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf122a2 <- subsetn(dta122,select=nms)

#lout122b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta122)
#summary(#lout122b)
##mf122b <- model.frame(#lout122b)

#lout122d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta122)
#summary(#lout122d)
##fv122d <- model.frame(#lout122d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv122a2 <- subsetn(dta122,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s122 <- subsetn(dta122,select=masterlist, subset=T)


##### August 2013
dta121 <- read.por.upper("hni121.por",to.data.frame=T)


dta121$INCOME <- NA
dta121$INCOME[dta121$QD14=="Less than $20,000"] <- 10
dta121$INCOME[dta121$QD14=="$20,000 to less than $30,000"] <- 25
dta121$INCOME[dta121$QD14=="$30,000 to less than $40,000"] <- 35
dta121$INCOME[dta121$QD14=="$40,000 to less than $50,000"] <- 45
dta121$INCOME[dta121$QD14=="$50,000 to less than $75,000"] <- 62.5
dta121$INCOME[dta121$QD14=="$75,000 to less than $90,000"] <- 82.5
dta121$INCOME[dta121$QD14=="$90,000 to less than $100,000"] <- 95
dta121$INCOME[dta121$QD14=="$100,000 or more"] <- 200

dta121$HISP <- (dta121$QD12=="Yes")*1

dta121$EDUC <- NA
dta121$EDUC[dta121$QD11=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta121$EDUC[dta121$QD11=="High school incomplete (Grades 9-11 or Grade 12 with NO diploma)"] <- 10
dta121$EDUC[dta121$QD11=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta121$EDUC[dta121$QD11=="Some college, no degree (includes some community college)"] <- 13
dta121$EDUC[dta121$QD11=="Two year associate degree from a college or university"] <- 14
dta121$EDUC[dta121$QD11=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta121$EDUC[dta121$QD11=="Some postgraduate or professional schooling, no postgraduate degree"] <- 17
dta121$EDUC[dta121$QD11=="Postgraduate or professional degree, including master's, doctorate, medical or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta121$PID <- NA
dta121$PID[dta121$QD8=="Democrat"] <- 1
dta121$PID[dta121$QD8 %in% c("Independent","Or what?")] <- 2
dta121$PID[dta121$QD8=="Republican"] <- 3

dta121$PID5 <- NA
dta121$PID5[dta121$PID==1] <- 1
dta121$PID5[dta121$QD8A=="Democratic"] <- 2
dta121$PID5[dta121$QD8A %in% c("Independent/don't lean to either party (VOL.)", "Other party (VOL.)", "(DO NOT READ) Don't know/Refused")] <- 3
dta121$PID5[dta121$QD8A=="Republican"] <- 4
dta121$PID5[dta121$PID==3] <- 5


dta121$BETPER <- NA
dta121$BETPER[dta121$Q2A=="Better off"] <- 3
dta121$BETPER[dta121$Q2A=="No difference"] <- 2
dta121$BETPER[dta121$Q2A=="(DO NOT READ) Don't know/Refused"] <- 2
dta121$BETPER[dta121$Q2A=="Worse off"] <- 1

dta121$BETCOU <- NA
dta121$BETCOU[dta121$Q2B=="Better off"] <- 3
dta121$BETCOU[dta121$Q2B=="No difference"] <- 2
dta121$BETCOU[dta121$Q2B=="(DO NOT READ) Don't know/Refused"] <- 2
dta121$BETCOU[dta121$Q2B=="Worse off"] <- 1

# NOTE: var replaced with FAVOR var.
dta121$SUPPORT <- NA
#dta121$SUPPORT[dta121$Q1=="Strongly support"] <- 4
#dta121$SUPPORT[dta121$Q1=="Somewhat support"] <- 3
#dta121$SUPPORT[dta121$Q1=="Somewhat oppose"] <- 2
#dta121$SUPPORT[dta121$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta121$BLACK <- (dta121$QD13=="Black or African-American")*1
dta121$ASIAN <- (dta121$QD13=="Asian")*1
dta121$OTHER <- (dta121$QD13=="Other or mixed race (SPECIFY)")*1

dta121$AGE <- dta121$QD5
dta121$AGE[dta121$AGE==99] <- NA
dta121$MEDICARE <- (dta121$AGE > 64)*1


dta121$COVERED <- (dta121$QD4=="Covered by health insurance")*1


dta121$IDEO <- NA
#dta121$IDEO[dta121$QD8B=="Liberal"] <- 3
#dta121$IDEO[dta121$QD8B=="Moderate"] <- 2
#dta121$IDEO[dta121$QD8B=="Conservative"] <- 1

dta121$FAVOR <- NA
dta121$FAVOR[dta121$Q1=="Very favorable"] <- 4
dta121$FAVOR[dta121$Q1=="Somewhat favorable"] <- 3
dta121$FAVOR[dta121$Q1=="Somewhat unfavorable"] <- 2
dta121$FAVOR[dta121$Q1=="Very unfavorable"] <- 1

# Question Still Not Asked
dta121$SELFEMPLOY <- NA
#dta121$SELFEMPLOY[dta121$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta121$RETIRED <- 0
dta121$RETIRED[dta121$QD3==" Retired"] <- 1

dta121$MEDICARESR <- 0
dta121$MEDICARESR <- 1*(dta121$QD4A=="Medicare")
dta121$MEDICARESR[dta121$QD4A %in% c(NA)] <- 0

dta121$MEDICAID <- 0
dta121$MEDICAID <- 1*(dta121$QD4A=="Medicaid/Medi-CAL")
dta121$MEDICAID[dta121$QD4A %in% c(NA)] <- 0


dta121$HEALTH <- NA
dta121$HEALTH[dta121$QD2=="Excellent"] <- 5
dta121$HEALTH[dta121$QD2=="Very good"] <- 4
dta121$HEALTH[dta121$QD2=="Good"] <- 3
dta121$HEALTH[dta121$QD2=="Only fair"] <- 2
dta121$HEALTH[dta121$QD2=="Poor"] <- 1

dta121$SAWAD <- NA
dta121$SAWADPOS <- NA
dta121$SAWADNEG <- NA
dta121$SAWADBOTH <- NA

dta121$SSTATE <- dta121$STATE

dta121$MALE <- 1*(dta121$QD1=="Male")

dta121$NUMBER <- 121

dta121$MARKET <- NA

dta121$MONTH <- 55

dta121$SELFINSURE <- 0
dta121$SELFINSURE[dta121$QD4A=="Plan you purchased yourself"]<-1

dta121$EMPLINSURE <- 0
dta121$EMPLINSURE[dta121$QD4A=="Plan through your employer"]<-1
dta121$EMPLINSURE[dta121$QD4A=="Plan through your spouse's employer"]<-1

dta121$PREEXIST <- 0
dta121$PREEXIST[dta121$Q32=="Yes, someone in household has pre-existing condition"]<-1

#sort(table(dta121$Q2CD[dta121$FAVOR==1]))/sum(sort(table(dta121$Q2CD[dta121$FAVOR==1])))

#lout121a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta121)
#summary(#lout121a)
##mf121a <- model.frame(#lout121a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf121a2 <- subsetn(dta121,select=nms)

#lout121b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta121)
#summary(#lout121b)
##mf121b <- model.frame(#lout121b)

#lout121d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta121)
#summary(#lout121d)
##fv121d <- model.frame(#lout121d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv121a2 <- subsetn(dta121,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s121 <- subsetn(dta121,select=masterlist, subset=T)


##### June 2013
dta120 <- read.por.upper("hni120.por",to.data.frame=T)


dta120$INCOME <- NA
dta120$INCOME[dta120$QD14=="Less than $20,000"] <- 10
dta120$INCOME[dta120$QD14=="$20,000 to less than $30,000"] <- 25
dta120$INCOME[dta120$QD14=="$30,000 to less than $40,000"] <- 35
dta120$INCOME[dta120$QD14=="$40,000 to less than $50,000"] <- 45
dta120$INCOME[dta120$QD14=="$50,000 to less than $75,000"] <- 62.5
dta120$INCOME[dta120$QD14=="$75,000 to less than $90,000"] <- 82.5
dta120$INCOME[dta120$QD14=="$90,000 to less than $100,000"] <- 95
dta120$INCOME[dta120$QD14=="$100,000 or more"] <- 200

dta120$HISP <- (dta120$QD12=="Yes")*1

dta120$EDUC <- NA
dta120$EDUC[dta120$QD11=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta120$EDUC[dta120$QD11=="High school incomplete (Grades 9-11 or Grade 12 with NO diploma)"] <- 10
dta120$EDUC[dta120$QD11=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta120$EDUC[dta120$QD11=="Some college, no degree (includes some community college)"] <- 13
dta120$EDUC[dta120$QD11=="Two year associate degree from a college or university"] <- 14
dta120$EDUC[dta120$QD11=="Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB)"] <- 16
dta120$EDUC[dta120$QD11=="Some postgraduate or professional schooling, no postgraduate degree"] <- 17
dta120$EDUC[dta120$QD11=="Postgraduate or professional degree, including master's, doctorate, medical or law degree (e.g., MA, MS, PhD, MD, JD)"] <- 19

dta120$PID <- NA
dta120$PID[dta120$QD8=="Democrat"] <- 1
dta120$PID[dta120$QD8 %in% c("Independent","Or what?")] <- 2
dta120$PID[dta120$QD8=="Republican"] <- 3

dta120$PID5 <- NA
dta120$PID5[dta120$PID==1] <- 1
dta120$PID5[dta120$QD8A=="Democratic"] <- 2
dta120$PID5[dta120$QD8A %in% c("Independent/don't lean to either party (VOL.)", "Other party (VOL.)", "(DO NOT READ) Don't know/Refused")] <- 3
dta120$PID5[dta120$QD8A=="Republican"] <- 4
dta120$PID5[dta120$PID==3] <- 5


dta120$BETPER <- NA
dta120$BETPER[dta120$Q3A=="Better off"] <- 3
dta120$BETPER[dta120$Q3A=="It won't make much difference"] <- 2
dta120$BETPER[dta120$Q3A=="(DO NOT READ) Don't know/Refused"] <- 2
dta120$BETPER[dta120$Q3A=="Worse off"] <- 1

dta120$BETCOU <- NA
dta120$BETCOU[dta120$Q3B=="Better off"] <- 3
dta120$BETCOU[dta120$Q3B=="It won't make much difference"] <- 2
dta120$BETCOU[dta120$Q3B=="(DO NOT READ) Don't know/Refused"] <- 2
dta120$BETCOU[dta120$Q3B=="Worse off"] <- 1

# NOTE: var replaced with FAVOR var.
dta120$SUPPORT <- NA
#dta120$SUPPORT[dta120$Q1=="Strongly support"] <- 4
#dta120$SUPPORT[dta120$Q1=="Somewhat support"] <- 3
#dta120$SUPPORT[dta120$Q1=="Somewhat oppose"] <- 2
#dta120$SUPPORT[dta120$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta120$BLACK <- (dta120$QD13=="Black or African-American")*1
dta120$ASIAN <- (dta120$QD13=="Asian")*1
dta120$OTHER <- (dta120$QD13=="Other or mixed race (SPECIFY)")*1

dta120$AGE <- dta120$QD5
dta120$AGE[dta120$AGE==99] <- NA
dta120$MEDICARE <- (dta120$AGE > 64)*1


dta120$COVERED <- (dta120$QD4=="Covered by health insurance")*1


dta120$IDEO <- NA
#dta120$IDEO[dta120$QD8B=="Liberal"] <- 3
#dta120$IDEO[dta120$QD8B=="Moderate"] <- 2
#dta120$IDEO[dta120$QD8B=="Conservative"] <- 1

dta120$FAVOR <- NA
dta120$FAVOR[dta120$Q1=="Very favorable"] <- 4
dta120$FAVOR[dta120$Q1=="Somewhat favorable"] <- 3
dta120$FAVOR[dta120$Q1=="Somewhat unfavorable"] <- 2
dta120$FAVOR[dta120$Q1=="Very unfavorable"] <- 1

# Question Still Not Asked
dta120$SELFEMPLOY <- NA
#dta120$SELFEMPLOY[dta120$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta120$RETIRED <- 0
dta120$RETIRED[dta120$QD3==" Retired"] <- 1

dta120$MEDICARESR <- 0
dta120$MEDICARESR <- 1*(dta120$QD4A=="Medicare")
dta120$MEDICARESR[dta120$QD4A %in% c(NA)] <- 0

dta120$MEDICAID <- 0
dta120$MEDICAID <- 1*(dta120$QD4A=="Medicaid/Medi-CAL")
dta120$MEDICAID[dta120$QD4A %in% c(NA)] <- 0

dta120$HEALTH <- NA
dta120$HEALTH[dta120$QD2=="Excellent"] <- 5
dta120$HEALTH[dta120$QD2=="Very good"] <- 4
dta120$HEALTH[dta120$QD2=="Good"] <- 3
dta120$HEALTH[dta120$QD2=="Only fair"] <- 2
dta120$HEALTH[dta120$QD2=="Poor"] <- 1

dta120$SAWAD <- NA
dta120$SAWADPOS <- NA
dta120$SAWADNEG <- NA
dta120$SAWADBOTH <- NA

dta120$SSTATE <- dta120$STATE

dta120$MALE <- 1*(dta120$QD1=="Male")

dta120$NUMBER <- 120

dta120$MARKET <- NA

dta120$MONTH <- 53

dta120$SELFINSURE <- 0
dta120$SELFINSURE[dta120$QD4A=="Plan you purchased yourself"]<-1

dta120$EMPLINSURE <- 0
dta120$EMPLINSURE[dta120$QD4A=="Plan through your employer"]<-1
dta120$EMPLINSURE[dta120$QD4A=="Plan through your spouse's employer"]<-1

dta120$PREEXIST <- 0
dta120$PREEXIST[dta120$Q27=="Yes, someone in household has pre-existing condition"]<-1

#sort(table(dta120$Q2CD[dta120$FAVOR==1]))/sum(sort(table(dta120$Q2CD[dta120$FAVOR==1])))

#lout120a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta120)
#summary(#lout120a)
##mf120a <- model.frame(#lout120a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf120a2 <- subsetn(dta120,select=nms)

#lout120b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta120)
#summary(#lout120b)
##mf120b <- model.frame(#lout120b)

#lout120d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta120)
#summary(#lout120d)
##fv120d <- model.frame(#lout120d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv120a2 <- subsetn(dta120,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s120 <- subsetn(dta120,select=masterlist, subset=T)


##### April 2013
# NOTE: This dataset was a problem, had to delete observation 178 to get it to work for some reason
dta119 <- read.csv.lower("hni119.csv")


dta119$INCOME <- NA
dta119$INCOME[dta119$qd14==1] <- 10
dta119$INCOME[dta119$qd14==2] <- 25
dta119$INCOME[dta119$qd14==3] <- 35
dta119$INCOME[dta119$qd14==4] <- 45
dta119$INCOME[dta119$qd14==5] <- 62.5
dta119$INCOME[dta119$qd14==6] <- 82.5
dta119$INCOME[dta119$qd14==7] <- 95
dta119$INCOME[dta119$qd14==8] <- 200

dta119$HISP <- (dta119$d12==1)*1

dta119$EDUC <- NA
dta119$EDUC[dta119$d11==1] <- 6
dta119$EDUC[dta119$d11==2] <- 10
dta119$EDUC[dta119$d11==3] <- 12
dta119$EDUC[dta119$d11==4] <- 13
dta119$EDUC[dta119$d11==5] <- 14
dta119$EDUC[dta119$d11==6] <- 16
dta119$EDUC[dta119$d11==7] <- 17
dta119$EDUC[dta119$d11==8] <- 19

dta119$PID <- NA
dta119$PID[dta119$qd8==2] <- 1
dta119$PID[dta119$qd8 %in% c(3,4)] <- 2
dta119$PID[dta119$qd8==1] <- 3

dta119$PID5 <- NA
dta119$PID5[dta119$PID==1] <- 1
dta119$PID5[dta119$qd8a==2] <- 2
dta119$PID5[dta119$qd8a %in% c(3, 4, 9)] <- 3
dta119$PID5[dta119$qd8a==1] <- 4
dta119$PID5[dta119$PID==3] <- 5


dta119$BETPER <- NA

dta119$BETCOU <- NA
#dta119$BETCOU[dta119$Q3B=="Better off"] <- 3
#dta119$BETCOU[dta119$Q3B=="It won't make much difference"] <- 2
#dta119$BETCOU[dta119$Q3B=="(DO NOT READ) Don't know/Refused"] <- 2
#dta119$BETCOU[dta119$Q3B=="Worse off"] <- 1

# NOTE: var replaced with FAVOR var.
dta119$SUPPORT <- NA
#dta119$SUPPORT[dta119$Q1=="Strongly support"] <- 4
#dta119$SUPPORT[dta119$Q1=="Somewhat support"] <- 3
#dta119$SUPPORT[dta119$Q1=="Somewhat oppose"] <- 2
#dta119$SUPPORT[dta119$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta119$BLACK <- (dta119$d13==2)*1
dta119$ASIAN <- (dta119$d13==3)*1
dta119$OTHER <- (dta119$d13==4)*1

dta119$AGE <- as.numeric(dta119$d5)
dta119$AGE[dta119$d5==99] <- NA
dta119$MEDICARE <- (dta119$AGE > 64)*1


dta119$COVERED <- (dta119$qd4==1)*1


dta119$IDEO <- NA
#dta119$IDEO[dta119$QD8B=="Liberal"] <- 3
#dta119$IDEO[dta119$QD8B=="Moderate"] <- 2
#dta119$IDEO[dta119$QD8B=="Conservative"] <- 1

#dta119$IDEO <- NA

dta119$FAVOR <- NA
dta119$FAVOR[dta119$q1==1] <- 4
dta119$FAVOR[dta119$q1==2] <- 3
dta119$FAVOR[dta119$q1==3] <- 2
dta119$FAVOR[dta119$q1==4] <- 1

# Question Still Not Asked
dta119$SELFEMPLOY <- NA
#dta119$SELFEMPLOY[dta119$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta119$RETIRED <- 0
dta119$RETIRED[dta119$qd3==6] <- 1

dta119$MEDICARESR <- 0
dta119$MEDICARESR <- 1*(dta119$qd4a==3)
dta119$MEDICARESR[dta119$qd4a %in% c(NA)] <- 0

dta119$MEDICAID <- 0
dta119$MEDICAID <- 1*(dta119$qd4a==4)
dta119$MEDICAID[dta119$qd4a %in% c(NA)] <- 0


dta119$HEALTH <- NA
#dta119$HEALTH[dta119$QD2=="Excellent"] <- 5
#dta119$HEALTH[dta119$QD2=="Very good"] <- 4
#dta119$HEALTH[dta119$QD2=="Good"] <- 3
#dta119$HEALTH[dta119$QD2=="Only fair"] <- 2
#dta119$HEALTH[dta119$QD2=="Poor"] <- 1

#dta119$HEALTH <- NA

dta119$SAWAD <- NA
dta119$SAWADPOS <- NA
dta119$SAWADNEG <- NA
dta119$SAWADBOTH <- NA

dta119$SSTATE <- as.factor(dta119$state)

dta119$MALE <- 1*(dta119$d1==1)

dta119$NUMBER <- 119

dta119$MARKET <- NA

dta119$MONTH <- 51
dta119$REGISTERED <- NA

dta119$SELFINSURE <- 0
dta119$SELFINSURE[dta119$qd4a==2]<-1

dta119$EMPLINSURE <- 0
dta119$EMPLINSURE[dta119$qd4a==1]<-1

dta119$PREEXIST <- 0
dta119$PREEXIST[dta119$qd4b==1]<-1

#sort(table(dta119$Q2CD[dta119$FAVOR==1]))/sum(sort(table(dta119$Q2CD[dta119$FAVOR==1])))

###lout119a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta119)
##summary(#lout119a)
###mf119a <- model.frame(#lout119a)

#### full data
#nms <- c("MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
##mf119a2 <- subsetn(dta119,select=nms)

###lout119b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta119)
##summary(#lout119b)
###mf119b <- model.frame(#lout119b)

#lout119d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta119)
#summary(#lout119d)
##fv119d <- model.frame(#lout119d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv119a2 <- subsetn(dta119,select=fvnms)

dta119$PSRAID <- dta119$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s119 <- subsetn(dta119,select=masterlist, subset=T)

##### March 2013
dta118 <- read.csv.lower("hni118.csv")

dta118$REGISTERED <- NA

dta118$INCOME <- NA
dta118$INCOME[dta118$qd14==1] <- 10
dta118$INCOME[dta118$qd14==2] <- 25
dta118$INCOME[dta118$qd14==3] <- 35
dta118$INCOME[dta118$qd14==4] <- 45
dta118$INCOME[dta118$qd14==5] <- 62.5
dta118$INCOME[dta118$qd14==6] <- 82.5
dta118$INCOME[dta118$qd14==7] <- 95
dta118$INCOME[dta118$qd14==8] <- 200

dta118$HISP2 <- dta118$qd12
dta118$HISP <- (dta118$HISP2==1)*1

dta118$EDUC <- NA
dta118$EDUC[dta118$qd11==1] <- 6
dta118$EDUC[dta118$qd11==2] <- 10
dta118$EDUC[dta118$qd11==3] <- 12
dta118$EDUC[dta118$qd11==4] <- 13
dta118$EDUC[dta118$qd11==5] <- 14
dta118$EDUC[dta118$qd11==6] <- 16
dta118$EDUC[dta118$qd11==7] <- 17
dta118$EDUC[dta118$qd11==8] <- 19

dta118$PID <- NA
dta118$PID[dta118$qd8==2] <- 1
dta118$PID[dta118$qd8>=3 & dta118$qd8<=4] <- 2
dta118$PID[dta118$qd8==1] <- 3

dta118$PID5 <- NA
dta118$PID5[dta118$PID==1] <- 1
dta118$PID5[dta118$qd8a==2] <- 2
dta118$PID5[dta118$qd8a %in% c(3, 4, 9)] <- 3
dta118$PID5[dta118$qd8a==1] <- 4
dta118$PID5[dta118$PID==3] <- 5

dta118$BETPER <- NA
dta118$BETPER[dta118$Q3=="Better off"] <- 3
dta118$BETPER[dta118$Q3=="No difference"] <- 2
dta118$BETPER[dta118$Q3=="(DO NOT READ) Don"] <- 2
dta118$BETPER[dta118$Q3=="Worse off"] <- 1

dta118$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta118$SUPPORT <- NA
#dta118$SUPPORT[dta118$Q1=="Strongly support"] <- 4
#dta118$SUPPORT[dta118$Q1=="Somewhat support"] <- 3
#dta118$SUPPORT[dta118$Q1=="Somewhat oppose"] <- 2
#dta118$SUPPORT[dta118$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta118$BLACK <- (dta118$qd13==2)*1
dta118$ASIAN <- (dta118$qd13==3)*1
dta118$OTHER <- (dta118$qd13==4)*1

dta118$AGE <- dta118$qd5
dta118$AGE[dta118$AGE==99] <- NA
dta118$MEDICARE <- (dta118$AGE > 64)*1

dta118$COVERED <- (dta118$qd4==1)*1

dta118$IDEO <- NA

dta118$FAVOR <- NA
dta118$FAVOR[dta118$q1==1] <- 4
dta118$FAVOR[dta118$q1==2] <- 3
dta118$FAVOR[dta118$q1==3] <- 2
dta118$FAVOR[dta118$q1==4] <- 1

# Question Still Not Asked
dta118$SELFEMPLOY <- NA
#dta118$SELFEMPLOY[dta118$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta118$RETIRED <- 0
dta118$RETIRED[dta118$qd3==6] <- 1

dta118$MEDICARESR <- 0
dta118$MEDICARESR <- 1*(dta118$qd4a==3)
dta118$MEDICARESR[dta118$COVERED==0] <- 0

dta118$MEDICAID <- 0
dta118$MEDICAID <- 1*(dta118$qd4a==4)
dta118$MEDICAID[dta118$COVERED==0] <- 0

dta118$HEALTH <- NA

dta118$SAWAD <- NA
dta118$SAWADPOS <- NA
dta118$SAWADNEG <- NA
dta118$SAWADBOTH <- NA

dta118$SSTATE <- dta118$state
dta118$STATE <- dta118$state

dta118$MALE <- 1*(dta118$qd1==1)

dta118$NUMBER <- 118

dta118$MONTH <- 50

dta118$MARKET <- NA

dta118$SELFINSURE <- 0
dta118$SELFINSURE[dta118$qd4a==2]<-1
dta118$SELFINSURE[dta118$COVERED==0] <- 0

dta118$EMPLINSURE <- 0
dta118$EMPLINSURE[dta118$qd4a==1]<-1
dta118$EMPLINSURE[dta118$COVERED==0] <- 0

dta118$PREEXIST <- 0
dta118$PREEXIST[dta118$qd4b==1]<-1


#sort(table(dta118$Q2CD[dta118$FAVOR==1]))/sum(sort(table(dta118$Q2CD[dta118$FAVOR==1])))

#lout118a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta118)
#summary(#lout118a)
##mf118a <- model.frame(#lout118a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf118a2 <- subsetn(dta118,select=nms)

#lout118b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta118)
#summary(#lout118b)
##mf118b <- model.frame(#lout118b)

#lout118d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta118)
#summary(#lout118d)
##fv118d <- model.frame(#lout118d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv118a2 <- subsetn(dta118,select=fvnms)

dta118$PSRAID <- dta118$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s118 <- subsetn(dta118,select=masterlist, subset=T)


##### February 2013
dta117 <- read.por.upper("hni117.por",to.data.frame=T)


dta117$INCOME <- NA
dta117$INCOME[dta117$QD14=="Less than $20,000"] <- 10
dta117$INCOME[dta117$QD14=="$20,000 to less than $30,000"] <- 25
dta117$INCOME[dta117$QD14=="$30,000 to less than $40,000"] <- 35
dta117$INCOME[dta117$QD14=="$40,000 to less than $50,000"] <- 45
dta117$INCOME[dta117$QD14=="$50,000 to less than $75,000"] <- 62.5
dta117$INCOME[dta117$QD14=="$75,000 to less than $90,000"] <- 82.5
dta117$INCOME[dta117$QD14=="$90,000 to less than $100,000"] <- 95
dta117$INCOME[dta117$QD14=="$100,000 or more"] <- 200

dta117$HISP <- (dta117$D12=="Yes")*1

dta117$EDUC <- NA
dta117$EDUC[dta117$D11=="Less than high school (Grades 1-8 or no formal schooling)"] <- 6
dta117$EDUC[dta117$D11=="High school incomplete (Grades 9-11 or Grade 12 with NO diploma)"] <- 10
dta117$EDUC[dta117$D11=="High school graduate (Grade 12 with diploma or GED certificate)"] <- 12
dta117$EDUC[dta117$D11=="Some college, no degree (includes some community college)"] <- 13
dta117$EDUC[dta117$D11=="Two year associate degree from a college or university"] <- 14
dta117$EDUC[dta117$D11=="Four year college or university degree/Bachelor"] <- 16
dta117$EDUC[dta117$D11=="Some postgraduate or professional schooling, no postgraduate degree"] <- 17
dta117$EDUC[dta117$D11=="Postgraduate or professional degree, including master"] <- 19

dta117$PID <- NA
dta117$PID[dta117$QD8=="Democrat"] <- 1
dta117$PID[dta117$QD8 %in% c("Independent","Or what?")] <- 2
dta117$PID[dta117$QD8=="Republican"] <- 3

dta117$PID5 <- NA
dta117$PID5[dta117$PID==1] <- 1
dta117$PID5[dta117$QD8A=="Democratic"] <- 2
dta117$PID5[dta117$QD8A %in% c("Independent/don't lean to either party (VOL.)", "Other party (VOL.)", "(DO NOT READ) Don't know/Refused")] <- 3
dta117$PID5[dta117$QD8A=="Republican"] <- 4
dta117$PID5[dta117$PID==3] <- 5

dta117$REGISTERED <- NA
dta117$REGISTERED[dta117$QD9=="Yes"] <- 1
dta117$REGISTERED[dta117$QD9=="No"] <- 2


dta117$BETPER <- NA
dta117$BETPER[dta117$Q3A=="Better off"] <- 3
dta117$BETPER[dta117$Q3A=="It won't make much difference"] <- 2
dta117$BETPER[dta117$Q3A=="(DO NOT READ) Don't know/Refused"] <- 2
dta117$BETPER[dta117$Q3A=="Worse off"] <- 1

dta117$BETCOU <- NA
dta117$BETCOU[dta117$Q3B=="Better off"] <- 3
dta117$BETCOU[dta117$Q3B=="It won't make much difference"] <- 2
dta117$BETCOU[dta117$Q3B=="(DO NOT READ) Don't know/Refused"] <- 2
dta117$BETCOU[dta117$Q3B=="Worse off"] <- 1

# NOTE: var replaced with FAVOR var.
dta117$SUPPORT <- NA
#dta117$SUPPORT[dta117$Q1=="Strongly support"] <- 4
#dta117$SUPPORT[dta117$Q1=="Somewhat support"] <- 3
#dta117$SUPPORT[dta117$Q1=="Somewhat oppose"] <- 2
#dta117$SUPPORT[dta117$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta117$BLACK <- (dta117$D13=="Black or African-American")*1
dta117$ASIAN <- (dta117$D13=="Asian")*1
dta117$OTHER <- (dta117$D13=="Other or mixed race (SPECIFY)")*1

dta117$AGE <- dta117$AGE
dta117$AGE[dta117$AGE==99] <- NA
dta117$MEDICARE <- (dta117$AGE > 64)*1


dta117$COVERED <- (dta117$QD4=="Covered by health insurance")*1


dta117$IDEO <- NA
dta117$IDEO[dta117$QD8B=="Liberal"] <- 3
dta117$IDEO[dta117$QD8B=="Moderate"] <- 2
dta117$IDEO[dta117$QD8B=="Conservative"] <- 1

dta117$FAVOR <- NA
dta117$FAVOR[dta117$Q1=="Very favorable"] <- 4
dta117$FAVOR[dta117$Q1=="Somewhat favorable"] <- 3
dta117$FAVOR[dta117$Q1=="Somewhat unfavorable"] <- 2
dta117$FAVOR[dta117$Q1=="Very unfavorable"] <- 1

# Question Still Not Asked
dta117$SELFEMPLOY <- NA
#dta117$SELFEMPLOY[dta117$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta117$RETIRED <- 0
dta117$RETIRED[dta117$QD3=="Retired"] <- 1

dta117$MEDICARESR <- 0
dta117$MEDICARESR <- 1*(dta117$QD4A=="Medicare")
dta117$MEDICARESR[dta117$QD4A %in% c(NA)] <- 0

dta117$MEDICAID <- 0
dta117$MEDICAID <- 1*(dta117$QD4A=="Medicaid/Medi-CAL")
dta117$MEDICAID[dta117$QD4A %in% c(NA)] <- 0

#HEALTH base data unavailable
dta117$HEALTH <- NA
#dta117$HEALTH[dta117$QD2=="Excellent"] <- 5
#dta117$HEALTH[dta117$QD2=="Very good"] <- 4
#dta117$HEALTH[dta117$QD2=="Good"] <- 3
#dta117$HEALTH[dta117$QD2=="Only fair"] <- 2
#dta117$HEALTH[dta117$QD2=="Poor"] <- 1

#dta117$HEALTH <- NA

dta117$SAWAD <- NA
dta117$SAWADPOS <- NA
dta117$SAWADNEG <- NA
dta117$SAWADBOTH <- NA

dta117$SSTATE <- dta117$STATE

dta117$MALE <- 1*(dta117$SEX=="Male")

dta117$NUMBER <- 117

dta117$MARKET <- NA

dta117$MONTH <- 49

dta117$SELFINSURE <- 0
dta117$SELFINSURE[dta117$QD4A=="Plan you purchased yourself"]<-1

dta117$EMPLINSURE <- 0
dta117$EMPLINSURE[dta117$QD4A=="Plan through your/your spouse's employer"]<-1

dta117$PREEXIST <- NA

#sort(table(dta117$Q2CD[dta117$FAVOR==1]))/sum(sort(table(dta117$Q2CD[dta117$FAVOR==1])))

#lout117a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta117)
#summary(#lout117a)
##mf117a <- model.frame(#lout117a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf117a2 <- subsetn(dta117,select=nms)

#lout117b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta117)
#summary(#lout117b)
##mf117b <- model.frame(#lout117b)

#lout117d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta117)
#summary(#lout117d)
##fv117d <- model.frame(#lout117d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv117a2 <- subsetn(dta117,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s117 <- subsetn(dta117,select=masterlist, subset=T)


##### November 2012
dta116 <- read.por.upper("hni116.por",to.data.frame=T)


dta116$INCOME <- NA
dta116$INCOME[dta116$QD14=="Less than $20,000"] <- 10
dta116$INCOME[dta116$QD14=="$20,000 to less than $30,000"] <- 25
dta116$INCOME[dta116$QD14=="$30,000 to less than $40,000"] <- 35
dta116$INCOME[dta116$QD14=="$40,000 to less than $50,000"] <- 45
dta116$INCOME[dta116$QD14=="$50,000 to less than $75,000"] <- 62.5
dta116$INCOME[dta116$QD14=="$75,000 to less than $90,000"] <- 82.5
dta116$INCOME[dta116$QD14=="$90,000 to less than $100,000"] <- 95
dta116$INCOME[dta116$QD14=="$100,000 or more"] <- 200

dta116$HISP <- (dta116$QD12=="Yes")*1

dta116$EDUC <- NA
dta116$EDUC[dta116$QD11=="None, or grade 1-8"] <- 6
dta116$EDUC[dta116$QD11=="High school incomplete (grades 9-11)"] <- 10
dta116$EDUC[dta116$QD11=="High school graduate (grade 12 or GED certificate)"] <- 12
dta116$EDUC[dta116$QD11=="Technical, trade or vocational school AFTER high school"] <- 13
dta116$EDUC[dta116$QD11=="Some college, no four-year degree (includes associate degree)"] <- 14
dta116$EDUC[dta116$QD11=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta116$EDUC[dta116$QD11=="Post-graduate or professional schooling after college"] <- 19

dta116$PID <- NA
dta116$PID[dta116$QD8=="Democrat"] <- 1
dta116$PID[dta116$QD8 %in% c("Independent","Or what?")] <- 2
dta116$PID[dta116$QD8=="Republican"] <- 3

dta116$PID5 <- NA
dta116$PID5[dta116$PID==1] <- 1
dta116$PID5[dta116$QD8A=="Democratic"] <- 2
dta116$PID5[dta116$QD8A %in% c("Independent/don't lean to either party (VOL.)", "Other party (VOL.)", "(DO NOT READ) Don't know/Refused")] <- 3
dta116$PID5[dta116$QD8A=="Republican"] <- 4
dta116$PID5[dta116$PID==3] <- 5

dta116$REGISTERED <- NA
dta116$REGISTERED[dta116$Q1=="Yes"] <- 1
dta116$REGISTERED[dta116$Q1=="No"] <- 2



dta116$BETPER <- NA
#dta116$BETPER[dta116$Q2A=="Better off"] <- 3
#dta116$BETPER[dta116$Q2A=="It won't make much difference"] <- 2
#dta116$BETPER[dta116$Q2A=="(DO NOT READ) Don't know/Refused"] <- 2
#dta116$BETPER[dta116$Q2A=="Worse off"] <- 1

dta116$BETCOU <- NA
#dta116$BETCOU[dta116$Q2B=="Better off"] <- 3
#dta116$BETCOU[dta116$Q2B=="It won't make much difference"] <- 2
#dta116$BETCOU[dta116$Q2B=="(DO NOT READ) Don't know/Refused"] <- 2
#dta116$BETCOU[dta116$Q2B=="Worse off"] <- 1

# NOTE: var replaced with FAVOR var.
dta116$SUPPORT <- NA
#dta116$SUPPORT[dta116$Q1=="Strongly support"] <- 4
#dta116$SUPPORT[dta116$Q1=="Somewhat support"] <- 3
#dta116$SUPPORT[dta116$Q1=="Somewhat oppose"] <- 2
#dta116$SUPPORT[dta116$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta116$BLACK <- (dta116$QD13=="Black or African-American")*1
dta116$ASIAN <- (dta116$QD13=="Asian")*1
dta116$OTHER <- (dta116$QD13=="Other or mixed race (SPECIFY)")*1

dta116$AGE <- dta116$AGE
dta116$AGE[dta116$AGE==99] <- NA
dta116$MEDICARE <- (dta116$AGE > 64)*1


dta116$COVERED <- (dta116$QD4=="Covered by health insurance")*1


dta116$IDEO <- NA
dta116$IDEO[dta116$QD8B=="Liberal"] <- 3
dta116$IDEO[dta116$QD8B=="Moderate"] <- 2
dta116$IDEO[dta116$QD8B=="Conservative"] <- 1

dta116$FAVOR <- NA
dta116$FAVOR[dta116$Q10=="Very favorable"] <- 4
dta116$FAVOR[dta116$Q10=="Somewhat favorable"] <- 3
dta116$FAVOR[dta116$Q10=="Somewhat unfavorable"] <- 2
dta116$FAVOR[dta116$Q10=="Very unfavorable"] <- 1

# Question Still Not Asked
dta116$SELFEMPLOY <- NA
#dta116$SELFEMPLOY[dta116$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta116$RETIRED <- 0
dta116$RETIRED[dta116$QD3=="Retired"] <- 1

dta116$MEDICARESR <- 0
dta116$MEDICARESR <- 1*(dta116$QD4A=="Medicare")
dta116$MEDICARESR[dta116$QD4A %in% c(NA)] <- 0

dta116$MEDICAID <- 0
dta116$MEDICAID <- 1*(dta116$QD4A=="Medicaid/Medi-CAL")
dta116$MEDICAID[dta116$QD4A %in% c(NA)] <- 0

#HEALTH base data unavailable
dta116$HEALTH <- NA
#dta116$HEALTH[dta116$QD2=="Excellent"] <- 5
#dta116$HEALTH[dta116$QD2=="Very good"] <- 4
#dta116$HEALTH[dta116$QD2=="Good"] <- 3
#dta116$HEALTH[dta116$QD2=="Only fair"] <- 2
#dta116$HEALTH[dta116$QD2=="Poor"] <- 1

#dta116$HEALTH <- NA

dta116$SAWAD <- NA
dta116$SAWADPOS <- NA
dta116$SAWADNEG <- NA
dta116$SAWADBOTH <- NA

dta116$SSTATE <- dta116$STATE

dta116$MALE <- 1*(dta116$QD1=="Male")

dta116$NUMBER <- 116

dta116$MARKET <- NA

dta116$MONTH <- 46

dta116$SELFINSURE <- 0
dta116$SELFINSURE[dta116$QD4A=="Plan you purchased yourself"]<-1

dta116$EMPLINSURE <- 0
dta116$EMPLINSURE[dta116$QD4A=="Plan through your/your spouse's employer"]<-1

dta116$PREEXIST <- NA

#sort(table(dta116$Q2CD[dta116$FAVOR==1]))/sum(sort(table(dta116$Q2CD[dta116$FAVOR==1])))

###lout116a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta116)
##summary(#lout116a)
###mf116a <- model.frame(#lout116a)

#### full data
#nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
##mf116a2 <- subsetn(dta116,select=nms)

###lout116b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta116)
##summary(#lout116b)
###mf116b <- model.frame(#lout116b)

#lout116d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta116)
#summary(#lout116d)
##fv116d <- model.frame(#lout116d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv116a2 <- subsetn(dta116,select=fvnms)


# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s116 <- subsetn(dta116,select=masterlist, subset=T)


##### October 2012
dta115 <- read.por.upper("hni115.por",to.data.frame=T)


dta115$INCOME <- NA
dta115$INCOME[dta115$QD14=="Less than $20,000"] <- 10
dta115$INCOME[dta115$QD14=="$20,000 to less than $30,000"] <- 25
dta115$INCOME[dta115$QD14=="$30,000 to less than $40,000"] <- 35
dta115$INCOME[dta115$QD14=="$40,000 to less than $50,000"] <- 45
dta115$INCOME[dta115$QD14=="$50,000 to less than $75,000"] <- 62.5
dta115$INCOME[dta115$QD14=="$75,000 to less than $90,000"] <- 82.5
dta115$INCOME[dta115$QD14=="$90,000 to less than $100,000"] <- 95
dta115$INCOME[dta115$QD14=="$100,000 or more"] <- 200

dta115$HISP <- (dta115$QD12=="Yes")*1

dta115$EDUC <- NA
dta115$EDUC[dta115$QD11=="None, or grade 1-8"] <- 6
dta115$EDUC[dta115$QD11=="High school incomplete (grades 9-11)"] <- 10
dta115$EDUC[dta115$QD11=="High school graduate (grade 12 or GED certificate)"] <- 12
dta115$EDUC[dta115$QD11=="Technical, trade or vocational school AFTER high school"] <- 13
dta115$EDUC[dta115$QD11=="Some college, no four-year degree (includes associate degree)"] <- 14
dta115$EDUC[dta115$QD11=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta115$EDUC[dta115$QD11=="Post-graduate or professional schooling after college"] <- 19

dta115$PID <- NA
dta115$PID[dta115$QD8=="Democrat"] <- 1
dta115$PID[dta115$QD8 %in% c("Independent","Or what?")] <- 2
dta115$PID[dta115$QD8=="Republican"] <- 3

dta115$PID5 <- NA
dta115$PID5[dta115$PID==1] <- 1
dta115$PID5[dta115$QD8A=="Democratic"] <- 2
dta115$PID5[dta115$QD8A %in% c("Independent/don't lean to either party (VOL.)", "Other party (VOL.)", "(DO NOT READ) Don't know/Refused")] <- 3
dta115$PID5[dta115$QD8A=="Republican"] <- 4
dta115$PID5[dta115$PID==3] <- 5


dta115$BETPER <- NA
dta115$BETPER[dta115$Q4A=="Better off"] <- 3
dta115$BETPER[dta115$Q4A=="It won't make much difference"] <- 2
dta115$BETPER[dta115$Q4A=="(DO NOT READ) Don't know/Refused"] <- 2
dta115$BETPER[dta115$Q4A=="Worse off"] <- 1

dta115$BETCOU <- NA
dta115$BETCOU[dta115$Q4B=="Better off"] <- 3
dta115$BETCOU[dta115$Q4B=="It won't make much difference"] <- 2
dta115$BETCOU[dta115$Q4B=="(DO NOT READ) Don't know/Refused"] <- 2
dta115$BETCOU[dta115$Q4B=="Worse off"] <- 1

# NOTE: var replaced with FAVOR var.
dta115$SUPPORT <- NA
#dta115$SUPPORT[dta115$Q1=="Strongly support"] <- 4
#dta115$SUPPORT[dta115$Q1=="Somewhat support"] <- 3
#dta115$SUPPORT[dta115$Q1=="Somewhat oppose"] <- 2
#dta115$SUPPORT[dta115$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta115$BLACK <- (dta115$QD13=="Black or African-American")*1
dta115$ASIAN <- (dta115$QD13=="Asian")*1
dta115$OTHER <- (dta115$QD13=="Other or mixed race (SPECIFY)")*1

dta115$AGE <- dta115$QD5
dta115$AGE[dta115$QD5==99] <- NA
dta115$MEDICARE <- (dta115$QD5 > 64)*1


dta115$COVERED <- (dta115$QD4=="Covered by health insurance")*1


dta115$IDEO <- NA
dta115$IDEO[dta115$QD8B=="Liberal"] <- 3
dta115$IDEO[dta115$QD8B=="Moderate"] <- 2
dta115$IDEO[dta115$QD8B=="Conservative"] <- 1

dta115$FAVOR <- NA
dta115$FAVOR[dta115$Q3=="Very favorable"] <- 4
dta115$FAVOR[dta115$Q3=="Somewhat favorable"] <- 3
dta115$FAVOR[dta115$Q3=="Somewhat unfavorable"] <- 2
dta115$FAVOR[dta115$Q3=="Very unfavorable"] <- 1

# Question Still Not Asked
dta115$SELFEMPLOY <- NA
#dta115$SELFEMPLOY[dta115$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta115$RETIRED <- NA
#dta115$RETIRED[dta115$QD3=="Retired"] <- 1

dta115$MEDICARESR <- 0
dta115$MEDICARESR <- 1*(dta115$QD4A=="Medicare")
dta115$MEDICARESR[dta115$QD4A %in% c(NA)] <- 0

dta115$MEDICAID <- 0
dta115$MEDICAID <- 1*(dta115$QD4A=="Medicaid/Medi-CAL")
dta115$MEDICAID[dta115$QD4A %in% c(NA)] <- 0


dta115$HEALTH <- NA
#dta115$HEALTH[dta115$QD2=="Excellent"] <- 5
#dta115$HEALTH[dta115$QD2=="Very good"] <- 4
#dta115$HEALTH[dta115$QD2=="Good"] <- 3
#dta115$HEALTH[dta115$QD2=="Only fair"] <- 2
#dta115$HEALTH[dta115$QD2=="Poor"] <- 1

#dta115$HEALTH <- NA

dta115$SAWAD <- NA
dta115$SAWADPOS <- NA
dta115$SAWADNEG <- NA
dta115$SAWADBOTH <- NA

dta115$SSTATE <- dta115$STATE

dta115$MALE <- 1*(dta115$QD1=="Male")

dta115$NUMBER <- 115

dta115$MARKET <- NA

dta115$MONTH <- 45

dta115$SELFINSURE <- 0
dta115$SELFINSURE[dta115$QD4A=="Plan you purchased yourself"]<-1

dta115$EMPLINSURE <- 0
dta115$EMPLINSURE[dta115$QD4A=="Plan through your/your spouse's employer"]<-1

dta115$PREEXIST <- NA

#sort(table(dta115$Q2CD[dta115$FAVOR==1]))/sum(sort(table(dta115$Q2CD[dta115$FAVOR==1])))

#lout115a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta115)
#summary(#lout115a)
##mf115a <- model.frame(#lout115a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf115a2 <- subsetn(dta115,select=nms)

#lout115b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta115)
#summary(#lout115b)
##mf115b <- model.frame(#lout115b)

#lout115d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta115)
#summary(#lout115d)
##fv115d <- model.frame(#lout115d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv115a2 <- subsetn(dta115,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s115 <- subsetn(dta115,select=masterlist, subset=T)

##### September 2012
dta114 <- read.por.upper("hni114.por",to.data.frame=T)


dta114$INCOME <- NA
dta114$INCOME[dta114$QD14=="Less than $20,000"] <- 10
dta114$INCOME[dta114$QD14=="$20,000 to less than $30,000"] <- 25
dta114$INCOME[dta114$QD14=="$30,000 to less than $40,000"] <- 35
dta114$INCOME[dta114$QD14=="$40,000 to less than $50,000"] <- 45
dta114$INCOME[dta114$QD14=="$50,000 to less than $75,000"] <- 62.5
dta114$INCOME[dta114$QD14=="$75,000 to less than $90,000"] <- 82.5
dta114$INCOME[dta114$QD14=="$90,000 to less than $100,000"] <- 95
dta114$INCOME[dta114$QD14=="$100,000 or more"] <- 200

dta114$HISP <- (dta114$QD12=="Yes")*1

dta114$EDUC <- NA
dta114$EDUC[dta114$QD11=="None, or grade 1-8"] <- 6
dta114$EDUC[dta114$QD11=="High school incomplete (grades 9-11)"] <- 10
dta114$EDUC[dta114$QD11=="High school graduate (grade 12 or GED certificate)"] <- 12
dta114$EDUC[dta114$QD11=="Technical, trade or vocational school AFTER high school"] <- 13
dta114$EDUC[dta114$QD11=="Some college, no four-year degree (includes associate degree)"] <- 14
dta114$EDUC[dta114$QD11=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta114$EDUC[dta114$QD11=="Post-graduate or professional schooling after college"] <- 19

dta114$PID <- NA
dta114$PID[dta114$QD8=="Democrat"] <- 1
dta114$PID[dta114$QD8 %in% c("Independent","Or what?")] <- 2
dta114$PID[dta114$QD8=="Republican"] <- 3

dta114$PID5 <- NA
dta114$PID5[dta114$PID==1] <- 1
dta114$PID5[dta114$QD8A=="Democratic"] <- 2
dta114$PID5[dta114$QD8A %in% c("Independent/don't lean to either party (VOL.)", "Other party (VOL.)", "(DO NOT READ) Don't know/Refused")] <- 3
dta114$PID5[dta114$QD8A=="Republican"] <- 4
dta114$PID5[dta114$PID==3] <- 5

dta114$REGISTERED <- NA
dta114$REGISTERED[dta114$QD9=="Yes"] <- 1
dta114$REGISTERED[dta114$QD9=="No"] <- 2


dta114$BETPER <- NA
dta114$BETPER[dta114$Q5A=="Better off"] <- 3
dta114$BETPER[dta114$Q5A=="It won't make much difference"] <- 2
dta114$BETPER[dta114$Q5A=="(DO NOT READ) Don't know/Refused"] <- 2
dta114$BETPER[dta114$Q5A=="Worse off"] <- 1

dta114$BETCOU <- NA
dta114$BETCOU[dta114$Q5B=="Better off"] <- 3
dta114$BETCOU[dta114$Q5B=="It won't make much difference"] <- 2
dta114$BETCOU[dta114$Q5B=="(DO NOT READ) Don't know/Refused"] <- 2
dta114$BETCOU[dta114$Q5B=="Worse off"] <- 1

# NOTE: var replaced with FAVOR var.
dta114$SUPPORT <- NA
#dta114$SUPPORT[dta114$Q1=="Strongly support"] <- 4
#dta114$SUPPORT[dta114$Q1=="Somewhat support"] <- 3
#dta114$SUPPORT[dta114$Q1=="Somewhat oppose"] <- 2
#dta114$SUPPORT[dta114$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta114$BLACK <- (dta114$QD13=="Black or African-American")*1
dta114$ASIAN <- (dta114$QD13=="Asian")*1
dta114$OTHER <- (dta114$QD13=="Other or mixed race (SPECIFY)")*1

dta114$AGE <- dta114$AGE
dta114$AGE[dta114$AGE==99] <- NA
dta114$MEDICARE <- (dta114$AGE > 64)*1


dta114$COVERED <- (dta114$QD4=="Covered by health insurance")*1


dta114$IDEO <- NA
dta114$IDEO[dta114$QD8B=="Liberal"] <- 3
dta114$IDEO[dta114$QD8B=="Moderate"] <- 2
dta114$IDEO[dta114$QD8B=="Conservative"] <- 1

dta114$FAVOR <- NA
dta114$FAVOR[dta114$Q4=="Very favorable"] <- 4
dta114$FAVOR[dta114$Q4=="Somewhat favorable"] <- 3
dta114$FAVOR[dta114$Q4=="Somewhat unfavorable"] <- 2
dta114$FAVOR[dta114$Q4=="Very unfavorable"] <- 1

# Question Still Not Asked
dta114$SELFEMPLOY <- NA
#dta114$SELFEMPLOY[dta114$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta114$RETIRED <- NA
#dta114$RETIRED[dta113$QD3=="Retired"] <- 1

dta114$MEDICARESR <- 0
dta114$MEDICARESR <- 1*(dta114$QD4A=="Medicare")
dta114$MEDICARESR[dta114$QD4A %in% c(NA)] <- 0

dta114$MEDICAID <- 0
dta114$MEDICAID <- 1*(dta114$QD4A=="Medicaid/Medi-CAL")
dta114$MEDICAID[dta114$QD4A %in% c(NA)] <- 0

#HEALTH base data unavailable
dta114$HEALTH <- NA
#dta114$HEALTH[dta114$QD2=="Excellent"] <- 5
#dta114$HEALTH[dta114$QD2=="Very good"] <- 4
#dta114$HEALTH[dta114$QD2=="Good"] <- 3
#dta114$HEALTH[dta114$QD2=="Only fair"] <- 2
#dta114$HEALTH[dta114$QD2=="Poor"] <- 1

#dta114$HEALTH <- NA

dta114$SAWAD <- NA
dta114$SAWADPOS <- NA
dta114$SAWADNEG <- NA
dta114$SAWADBOTH <- NA

dta114$SSTATE <- dta114$STATE

dta114$MALE <- 1*(dta114$QD1=="Male")

dta114$NUMBER <- 114

dta114$MARKET <- NA

dta114$MONTH <- 44

dta114$SELFINSURE <- 0
dta114$SELFINSURE[dta114$QD4A=="Plan you purchased yourself"]<-1

dta114$EMPLINSURE <- 0
dta114$EMPLINSURE[dta114$QD4A=="Plan through your/your spouse's employer"]<-1

dta114$PREEXIST <- NA

#sort(table(dta114$Q2CD[dta114$FAVOR==1]))/sum(sort(table(dta114$Q2CD[dta114$FAVOR==1])))

#lout114a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta114)
#summary(#lout114a)
##mf114a <- model.frame(#lout114a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf114a2 <- subsetn(dta114,select=nms)

#lout114b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta114)
#summary(#lout114b)
##mf114b <- model.frame(#lout114b)

#lout114d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta114)
#summary(#lout114d)
##fv114d <- model.frame(#lout114d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv114a2 <- subsetn(dta114,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s114 <- subsetn(dta114,select=masterlist, subset=T)


##### August 2012
dta113 <- read.por.upper("hni113.por",to.data.frame=T)


dta113$INCOME <- NA
dta113$INCOME[dta113$QD14=="Less than $20,000"] <- 10
dta113$INCOME[dta113$QD14=="$20,000 to less than $30,000"] <- 25
dta113$INCOME[dta113$QD14=="$30,000 to less than $40,000"] <- 35
dta113$INCOME[dta113$QD14=="$40,000 to less than $50,000"] <- 45
dta113$INCOME[dta113$QD14=="$50,000 to less than $75,000"] <- 62.5
dta113$INCOME[dta113$QD14=="$75,000 to less than $90,000"] <- 82.5
dta113$INCOME[dta113$QD14=="$90,000 to less than $100,000"] <- 95
dta113$INCOME[dta113$QD14=="$100,000 or more"] <- 200

dta113$HISP <- (dta113$QD12=="Yes")*1

dta113$EDUC <- NA
dta113$EDUC[dta113$QD11=="None, or grade 1-8"] <- 6
dta113$EDUC[dta113$QD11=="High school incomplete (grades 9-11)"] <- 10
dta113$EDUC[dta113$QD11=="High school graduate (grade 12 or GED certificate)"] <- 12
dta113$EDUC[dta113$QD11=="Technical, trade or vocational school AFTER high school"] <- 13
dta113$EDUC[dta113$QD11=="Some college, no four-year degree (includes associate degree)"] <- 14
dta113$EDUC[dta113$QD11=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta113$EDUC[dta113$QD11=="Post-graduate or professional schooling after college"] <- 19

dta113$PID <- NA
dta113$PID[dta113$QD8=="Democrat"] <- 1
dta113$PID[dta113$QD8 %in% c("Independent","Or what?")] <- 2
dta113$PID[dta113$QD8=="Republican"] <- 3

dta113$PID5 <- NA
dta113$PID5[dta113$PID==1] <- 1
dta113$PID5[dta113$QD8A=="Democratic"] <- 2
dta113$PID5[dta113$QD8A %in% c("Independent/don't lean to either party (VOL.)", "Other party (VOL.)", "(DO NOT READ) Don't know/Refused")] <- 3
dta113$PID5[dta113$QD8A=="Republican"] <- 4
dta113$PID5[dta113$PID==3] <- 5

dta113$REGISTERED <- NA
dta113$REGISTERED[dta113$QD9=="Yes"] <- 1
dta113$REGISTERED[dta113$QD9=="No"] <- 2


dta113$BETPER <- NA
dta113$BETPER[dta113$Q2A=="Better off"] <- 3
dta113$BETPER[dta113$Q2A=="It won't make much difference"] <- 2
dta113$BETPER[dta113$Q2A=="(DO NOT READ) Don't know/Refused"] <- 2
dta113$BETPER[dta113$Q2A=="Worse off"] <- 1

dta113$BETCOU <- NA
dta113$BETCOU[dta113$Q2B=="Better off"] <- 3
dta113$BETCOU[dta113$Q2B=="It won't make much difference"] <- 2
dta113$BETCOU[dta113$Q2B=="(DO NOT READ) Don't know/Refused"] <- 2
dta113$BETCOU[dta113$Q2B=="Worse off"] <- 1

# NOTE: var replaced with FAVOR var.
dta113$SUPPORT <- NA
#dta113$SUPPORT[dta113$Q1=="Strongly support"] <- 4
#dta113$SUPPORT[dta113$Q1=="Somewhat support"] <- 3
#dta113$SUPPORT[dta113$Q1=="Somewhat oppose"] <- 2
#dta113$SUPPORT[dta113$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta113$BLACK <- (dta113$QD13=="Black or African-American")*1
dta113$ASIAN <- (dta113$QD13=="Asian")*1
dta113$OTHER <- (dta113$QD13=="Other or mixed race (SPECIFY)")*1

dta113$AGE <- dta113$QD5
dta113$AGE[dta113$AGE==99] <- NA
dta113$MEDICARE <- (dta113$AGE > 64)*1


dta113$COVERED <- (dta113$QD4=="Covered by health insurance")*1


dta113$IDEO <- NA
dta113$IDEO[dta113$QD8B=="Liberal"] <- 3
dta113$IDEO[dta113$QD8B=="Moderate"] <- 2
dta113$IDEO[dta113$QD8B=="Conservative"] <- 1

dta113$FAVOR <- NA
dta113$FAVOR[dta113$Q1=="Very favorable"] <- 4
dta113$FAVOR[dta113$Q1=="Somewhat favorable"] <- 3
dta113$FAVOR[dta113$Q1=="Somewhat unfavorable"] <- 2
dta113$FAVOR[dta113$Q1=="Very unfavorable"] <- 1

# Question Still Not Asked
dta113$SELFEMPLOY <- NA
#dta113$SELFEMPLOY[dta113$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta113$RETIRED <- NA
#dta113$RETIRED[dta113$QD3=="Retired"] <- 1

dta113$MEDICARESR <- 0
dta113$MEDICARESR <- 1*(dta113$QD4A=="Medicare")
dta113$MEDICARESR[dta113$QD4A %in% c(NA)] <- 0

dta113$MEDICAID <- 0
dta113$MEDICAID <- 1*(dta113$QD4A=="Medicaid/Medi-CAL")
dta113$MEDICAID[dta113$QD4A %in% c(NA)] <- 0

#HEALTH base data unavailable
dta113$HEALTH <- NA
#dta113$HEALTH[dta113$QD2=="Excellent"] <- 5
#dta113$HEALTH[dta113$QD2=="Very good"] <- 4
#dta113$HEALTH[dta113$QD2=="Good"] <- 3
#dta113$HEALTH[dta113$QD2=="Only fair"] <- 2
#dta113$HEALTH[dta113$QD2=="Poor"] <- 1

dta113$SAWAD <- NA
dta113$SAWADPOS <- NA
dta113$SAWADNEG <- NA
dta113$SAWADBOTH <- NA

dta113$SSTATE <- dta113$STATE

dta113$MALE <- 1*(dta113$QD1=="Male")

dta113$NUMBER <- 113

dta113$MARKET <- NA

dta113$MONTH <- 43

dta113$SELFINSURE <- 0
dta113$SELFINSURE[dta113$QD4A=="Plan you purchased yourself"]<-1

dta113$EMPLINSURE <- 0
dta113$EMPLINSURE[dta113$QD4A=="Plan through your/your spouse's employer"]<-1

dta113$PREEXIST <- NA

#sort(table(dta113$Q2CD[dta113$FAVOR==1]))/sum(sort(table(dta113$Q2CD[dta113$FAVOR==1])))

#lout113a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta113)
#summary(#lout113a)
##mf113a <- model.frame(#lout113a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf113a2 <- subsetn(dta113,select=nms)

#lout113b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta113)
#summary(#lout113b)
##mf113b <- model.frame(#lout113b)

#lout113d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta113)
#summary(#lout113d)
##fv113d <- model.frame(#lout113d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv113a2 <- subsetn(dta113,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s113 <- subsetn(dta113,select=masterlist, subset=T)


##### July 2012
dta112 <- read.por.upper("hni112.por",to.data.frame=T)


dta112$INCOME <- NA
dta112$INCOME[dta112$QD14=="Less than $20,000"] <- 10
dta112$INCOME[dta112$QD14=="$20,000 to less than $30,000"] <- 25
dta112$INCOME[dta112$QD14=="$30,000 to less than $40,000"] <- 35
dta112$INCOME[dta112$QD14=="$40,000 to less than $50,000"] <- 45
dta112$INCOME[dta112$QD14=="$50,000 to less than $75,000"] <- 62.5
dta112$INCOME[dta112$QD14=="$75,000 to less than $90,000"] <- 82.5
dta112$INCOME[dta112$QD14=="$90,000 to less than $100,000"] <- 95
dta112$INCOME[dta112$QD14=="$100,000 or more"] <- 200

dta112$HISP <- (dta112$QD12=="Yes")*1

dta112$EDUC <- NA
dta112$EDUC[dta112$QD11=="None, or grade 1-8"] <- 6
dta112$EDUC[dta112$QD11=="High school incomplete (grades 9-11)"] <- 10
dta112$EDUC[dta112$QD11=="High school graduate (grade 12 or GED certificate)"] <- 12
dta112$EDUC[dta112$QD11=="Technical, trade or vocational school AFTER high school"] <- 13
dta112$EDUC[dta112$QD11=="Some college, no four-year degree (includes associate degree)"] <- 14
dta112$EDUC[dta112$QD11=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta112$EDUC[dta112$QD11=="Post-graduate or professional schooling after college"] <- 19

dta112$PID <- NA
dta112$PID[dta112$QD8=="Democrat"] <- 1
dta112$PID[dta112$QD8 %in% c("Independent","Or what?")] <- 2
dta112$PID[dta112$QD8=="Republican"] <- 3

dta112$PID5 <- NA
dta112$PID5[dta112$PID==1] <- 1
dta112$PID5[dta112$QD8A=="Democratic"] <- 2
dta112$PID5[dta112$QD8A %in% c("Independent/don't lean to either party (VOL.)", "Other party (VOL.)", "(DO NOT READ) Don't know/Refused")] <- 3
dta112$PID5[dta112$QD8A=="Republican"] <- 4
dta112$PID5[dta112$PID==3] <- 5

dta112$REGISTERED <- NA
dta112$REGISTERED[dta112$QD9=="Yes"] <- 1
dta112$REGISTERED[dta112$QD9=="No"] <- 2


dta112$BETPER <- NA
dta112$BETPER[dta112$Q2A=="Better off"] <- 3
dta112$BETPER[dta112$Q2A=="It won't make much difference"] <- 2
dta112$BETPER[dta112$Q2A=="(DO NOT READ) Don't know/Refused"] <- 2
dta112$BETPER[dta112$Q2A=="Worse off"] <- 1

dta112$BETCOU <- NA
dta112$BETCOU[dta112$Q2B=="Better off"] <- 3
dta112$BETCOU[dta112$Q2B=="It won't make much difference"] <- 2
dta112$BETCOU[dta112$Q2B=="(DO NOT READ) Don't know/Refused"] <- 2
dta112$BETCOU[dta112$Q2B=="Worse off"] <- 1

# NOTE: var replaced with FAVOR var.
dta112$SUPPORT <- NA
#dta112$SUPPORT[dta112$Q1=="Strongly support"] <- 4
#dta112$SUPPORT[dta112$Q1=="Somewhat support"] <- 3
#dta112$SUPPORT[dta112$Q1=="Somewhat oppose"] <- 2
#dta112$SUPPORT[dta112$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta112$BLACK <- (dta112$QD13=="Black or African-American")*1
dta112$ASIAN <- (dta112$QD13=="Asian")*1
dta112$OTHER <- (dta112$QD13=="Other or mixed race (SPECIFY)")*1

dta112$AGE <- dta112$QD5
dta112$AGE[dta112$QD5==99] <- NA
dta112$MEDICARE <- (dta112$AGE > 64)*1


dta112$COVERED <- (dta112$QD4=="Covered by health insurance")*1


dta112$IDEO <- NA
dta112$IDEO[dta112$QD8B=="Liberal"] <- 3
dta112$IDEO[dta112$QD8B=="Moderate"] <- 2
dta112$IDEO[dta112$QD8B=="Conservative"] <- 1


dta112$FAVOR <- NA
dta112$FAVOR[dta112$Q1=="Very favorable"] <- 4
dta112$FAVOR[dta112$Q1=="Somewhat favorable"] <- 3
dta112$FAVOR[dta112$Q1=="Somewhat unfavorable"] <- 2
dta112$FAVOR[dta112$Q1=="Very unfavorable"] <- 1

# Question Still Not Asked
dta112$SELFEMPLOY <- NA
#dta112$SELFEMPLOY <- 0
#dta112$SELFEMPLOY[dta112$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta112$RETIRED <- NA
#dta112$RETIRED <- 0
#dta112$RETIRED[dta112$QD3=="Retired"] <- 1

dta112$MEDICARESR <- 0
dta112$MEDICARESR <- 1*(dta112$QD4A=="Medicare")
dta112$MEDICARESR[dta112$QD4A %in% c(NA)] <- 0

dta112$MEDICAID <- 0
dta112$MEDICAID <- 1*(dta112$QD4A=="Medicaid/Medi-CAL")
dta112$MEDICAID[dta112$QD4A %in% c(NA)] <- 0

#HEALTH base data unavailable
dta112$HEALTH <- NA
#dta112$HEALTH[dta112$QD2=="Excellent"] <- 5
#dta112$HEALTH[dta112$QD2=="Very good"] <- 4
#dta112$HEALTH[dta112$QD2=="Good"] <- 3
#dta112$HEALTH[dta112$QD2=="Only fair"] <- 2
#dta112$HEALTH[dta112$QD2=="Poor"] <- 1

#dta112$HEALTH <- NA

dta112$SAWAD <- NA
dta112$SAWADPOS <- NA
dta112$SAWADNEG <- NA
dta112$SAWADBOTH <- NA

dta112$SSTATE <- dta112$STATE

dta112$MALE <- 1*(dta112$QD1=="Male")

dta112$NUMBER <- 112

dta112$MARKET <- NA

dta112$MONTH <- 42

dta112$SELFINSURE <- 0
dta112$SELFINSURE[dta112$QD4A=="Plan you purchased yourself"]<-1

dta112$EMPLINSURE <- 0
dta112$EMPLINSURE[dta112$QD4A=="Plan through your/your spouse's employer"]<-1

dta112$PREEXIST <- NA

#sort(table(dta112$Q2CD[dta112$FAVOR==1]))/sum(sort(table(dta112$Q2CD[dta112$FAVOR==1])))

#lout112a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta112)
#summary(#lout112a)
##mf112a <- model.frame(#lout112a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf112a2 <- subsetn(dta112,select=nms)

#lout112b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta112)
#summary(#lout112b)
##mf112b <- model.frame(#lout112b)

#lout112d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta112)
#summary(#lout112d)
##fv112d <- model.frame(#lout112d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv112a2 <- subsetn(dta112,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s112 <- subsetn(dta112,select=masterlist, subset=T)


###### June 2012
dta111 <- read.por.upper("hni111.por",to.data.frame=T)


dta111$INCOME <- NA
dta111$INCOME[dta111$QD14=="Less than $20,000"] <- 10
dta111$INCOME[dta111$QD14=="$20,000 to less than $30,000"] <- 25
dta111$INCOME[dta111$QD14=="$30,000 to less than $40,000"] <- 35
dta111$INCOME[dta111$QD14=="$40,000 to less than $50,000"] <- 45
dta111$INCOME[dta111$QD14=="$50,000 to less than $75,000"] <- 62.5
dta111$INCOME[dta111$QD14=="$75,000 to less than $90,000"] <- 82.5
dta111$INCOME[dta111$QD14=="$90,000 to less than $100,000"] <- 95
dta111$INCOME[dta111$QD14=="$100,000 or more"] <- 200

dta111$HISP <- (dta111$QD12=="Yes")*1

dta111$EDUC <- NA
dta111$EDUC[dta111$QD11=="None, or grade 1-8"] <- 6
dta111$EDUC[dta111$QD11=="High school incomplete (grades 9-11)"] <- 10
dta111$EDUC[dta111$QD11=="High school graduate (grade 12 or GED certificate)"] <- 12
dta111$EDUC[dta111$QD11=="Technical, trade or vocational school AFTER high school"] <- 13
dta111$EDUC[dta111$QD11=="Some college, no four-year degree (includes associate degree)"] <- 14
dta111$EDUC[dta111$QD11=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta111$EDUC[dta111$QD11=="Post-graduate or professional schooling after college"] <- 19

dta111$PID <- NA
dta111$PID[dta111$QD8=="Democrat"] <- 1
dta111$PID[dta111$QD8 %in% c("Independent","Or what?")] <- 2
dta111$PID[dta111$QD8=="Republican"] <- 3

dta111$PID5 <- NA
dta111$PID5[dta111$PID==1] <- 1
dta111$PID5[dta111$QD8A=="Democratic"] <- 2
dta111$PID5[dta111$QD8A %in% c("Independent/don't lean to either party (VOL.)", "Other party (VOL.)", "(DO NOT READ) Don't know/Refused")] <- 3
dta111$PID5[dta111$QD8A=="Republican"] <- 4
dta111$PID5[dta111$PID==3] <- 5

dta111$REGISTERED <- NA
dta111$REGISTERED[dta111$QD9=="Yes"] <- 1
dta111$REGISTERED[dta111$QD9=="No"] <- 2

## no version of this Q asked in this survey!
dta111$BETPER <- NA


dta111$BETCOU <- NA


dta111$SUPPORT <- NA
#dta111$SUPPORT[dta111$Q1=="Strongly support"] <- 4
#dta111$SUPPORT[dta111$Q1=="Somewhat support"] <- 3
#dta111$SUPPORT[dta111$Q1=="Somewhat oppose"] <- 2
#dta111$SUPPORT[dta111$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta111$BLACK <- (dta111$QD13=="Black or African-American")*1
dta111$ASIAN <- (dta111$QD13=="Asian")*1
dta111$OTHER <- (dta111$QD13=="Other or mixed race (SPECIFY)")*1

dta111$AGE <- dta111$AGE
dta111$AGE[dta111$AGE==99] <- NA
dta111$MEDICARE <- (dta111$AGE > 64)*1


dta111$COVERED <- (dta111$QD4=="Covered by health insurance")*1


dta111$IDEO <- NA
dta111$IDEO[dta111$QD8B=="Liberal"] <- 3
dta111$IDEO[dta111$QD8B=="Moderate"] <- 2
dta111$IDEO[dta111$QD8B=="Conservative"] <- 1


dta111$FAVOR <- NA
dta111$FAVOR[dta111$Q1=="Very favorable"] <- 4
dta111$FAVOR[dta111$Q1=="Somewhat favorable"] <- 3
dta111$FAVOR[dta111$Q1=="Somewhat unfavorable"] <- 2
dta111$FAVOR[dta111$Q1=="Very unfavorable"] <- 1

# Question Still Not Asked
dta111$SELFEMPLOY <- NA
#dta111$SELFEMPLOY[dta109$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta111$RETIRED <- NA
#dta109$RETIRED[dta109$QD3=="Retired"] <- 1

dta111$MEDICARESR <- 0
dta111$MEDICARESR <- 1*(dta111$QD4A=="Medicare")
dta111$MEDICARESR[dta111$QD4A %in% c(NA)] <- 0

dta111$MEDICAID <- 0
dta111$MEDICAID <- 1*(dta111$QD4A=="Medicaid/Medi-CAL")
dta111$MEDICAID[dta111$QD4A %in% c(NA)] <- 0

#HEALTH base data unavailable
dta111$HEALTH <- NA
#dta111$HEALTH[dta111$QD2=="Excellent"] <- 5
#dta111$HEALTH[dta111$QD2=="Very good"] <- 4
#dta111$HEALTH[dta111$QD2=="Good"] <- 3
#dta111$HEALTH[dta111$QD2=="Only fair"] <- 2
#dta111$HEALTH[dta111$QD2=="Poor"] <- 1

#dta111$HEALTH <- NA

dta111$SAWAD <- NA
dta111$SAWADPOS <- NA
dta111$SAWADNEG <- NA
dta111$SAWADBOTH <- NA

dta111$SSTATE <- dta111$STATE

dta111$MALE <- 1*(dta111$QD1=="Male")

dta111$NUMBER <- 111

dta111$MARKET <- NA

dta111$MONTH <- 41

dta111$SELFINSURE <- 0
dta111$SELFINSURE[dta111$QD4A=="Plan you purchased yourself"]<-1

dta111$EMPLINSURE <- 0
dta111$EMPLINSURE[dta111$QD4A=="Plan through your/your spouse's employer"]<-1

dta111$PREEXIST <- NA

#sort(table(dta111$Q2CD[dta111$FAVOR==1]))/sum(sort(table(dta111$Q2CD[dta111$FAVOR==1])))

###lout111a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta111)
##summary(#lout111a)
###mf111a <- model.frame(#lout111a)

#### full data
#nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
##mf111a2 <- subsetn(dta111,select=nms)

###lout111b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta111)
##summary(#lout111b)
###mf111b <- model.frame(#lout111b)

#lout111d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta111)
#summary(#lout111d)
##fv111d <- model.frame(#lout111d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv111a2 <- subsetn(dta111,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s111 <- subsetn(dta111,select=masterlist, subset=T)


##### May 2012
dta110 <- read.por.upper("hni110.por",to.data.frame=T)


dta110$INCOME <- NA
dta110$INCOME[dta110$QD14=="Less than $20,000"] <- 10
dta110$INCOME[dta110$QD14=="$20,000 to less than $30,000"] <- 25
dta110$INCOME[dta110$QD14=="$30,000 to less than $40,000"] <- 35
dta110$INCOME[dta110$QD14=="$40,000 to less than $50,000"] <- 45
dta110$INCOME[dta110$QD14=="$50,000 to less than $75,000"] <- 62.5
dta110$INCOME[dta110$QD14=="$75,000 to less than $90,000"] <- 82.5
dta110$INCOME[dta110$QD14=="$90,000 to less than $100,000"] <- 95
dta110$INCOME[dta110$QD14=="$100,000 or more"] <- 200

dta110$HISP <- (dta110$QD12=="Yes")*1

dta110$EDUC <- NA
dta110$EDUC[dta110$QD11=="None, or grade 1-8"] <- 6
dta110$EDUC[dta110$QD11=="High school incomplete (grades 9-11)"] <- 10
dta110$EDUC[dta110$QD11=="High school graduate (grade 12 or GED certificate)"] <- 12
dta110$EDUC[dta110$QD11=="Technical, trade or vocational school AFTER high school"] <- 13
dta110$EDUC[dta110$QD11=="Some college, no four-year degree (includes associate degree)"] <- 14
dta110$EDUC[dta110$QD11=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta110$EDUC[dta110$QD11=="Post-graduate or professional schooling after college"] <- 19

dta110$PID <- NA
dta110$PID[dta110$QD8=="Democrat"] <- 1
dta110$PID[dta110$QD8 %in% c("Independent","Or what?")] <- 2
dta110$PID[dta110$QD8=="Republican"] <- 3

dta110$PID5 <- NA
dta110$PID5[dta110$PID==1] <- 1
dta110$PID5[dta110$QD8A=="Democratic"] <- 2
dta110$PID5[dta110$QD8A %in% c("Independent/don't lean to either party (VOL.)", "Other party (VOL.)", "(DO NOT READ) Don't know/Refused")] <- 3
dta110$PID5[dta110$QD8A=="Republican"] <- 4
dta110$PID5[dta110$PID==3] <- 5

dta110$REGISTERED <- NA
dta110$REGISTERED[dta110$QD9=="Yes"] <- 1
dta110$REGISTERED[dta110$QD9=="No"] <- 2


dta110$BETPER <- NA
dta110$BETPER[dta110$Q3A=="Better off"] <- 3
dta110$BETPER[dta110$Q3A=="It won't make much difference"] <- 2
dta110$BETPER[dta110$Q3A=="(DO NOT READ) Don't know/Refused"] <- 2
dta110$BETPER[dta110$Q3A=="Worse off"] <- 1

dta110$BETCOU <- NA
dta110$BETCOU[dta110$Q3B=="Better off"] <- 3
dta110$BETCOU[dta110$Q3B=="It won't make much difference"] <- 2
dta110$BETCOU[dta110$Q3B=="(DO NOT READ) Don't know/Refused"] <- 2
dta110$BETCOU[dta110$Q3B=="Worse off"] <- 1

# NOTE: var replaced with FAVOR var.
dta110$SUPPORT <- NA
#dta110$SUPPORT[dta110$Q1=="Strongly support"] <- 4
#dta110$SUPPORT[dta110$Q1=="Somewhat support"] <- 3
#dta110$SUPPORT[dta110$Q1=="Somewhat oppose"] <- 2
#dta110$SUPPORT[dta110$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta110$BLACK <- (dta110$QD13=="Black or African-American")*1
dta110$ASIAN <- (dta110$QD13=="Asian")*1
dta110$OTHER <- (dta110$QD13=="Other or mixed race (SPECIFY)")*1

dta110$AGE <- dta110$QD5
dta110$AGE[dta110$QD5==99] <- NA
dta110$MEDICARE <- (dta110$AGE > 64)*1


dta110$COVERED <- (dta110$QD4=="Covered by health insurance")*1


dta110$IDEO <- NA
dta110$IDEO[dta110$QD8B=="Liberal"] <- 3
dta110$IDEO[dta110$QD8B=="Moderate"] <- 2
dta110$IDEO[dta110$QD8B=="Conservative"] <- 1

dta110$FAVOR <- NA
dta110$FAVOR[dta110$Q2=="Very favorable"] <- 4
dta110$FAVOR[dta110$Q2=="Somewhat favorable"] <- 3
dta110$FAVOR[dta110$Q2=="Somewhat unfavorable"] <- 2
dta110$FAVOR[dta110$Q2=="Very unfavorable"] <- 1

# Question Still Not Asked
dta110$SELFEMPLOY <- NA
#dta110$SELFEMPLOY[dta110$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta110$RETIRED <- 0
dta110$RETIRED[dta110$QD3=="Retired"] <- 1

dta110$MEDICARESR <- 0
dta110$MEDICARESR <- 1*(dta110$QD4A=="Medicare")
dta110$MEDICARESR[dta110$QD4A %in% c(NA)] <- 0

dta110$MEDICAID <- 0
dta110$MEDICAID <- 1*(dta110$QD4A=="Medicaid/Medi-CAL")
dta110$MEDICAID[dta110$QD4A %in% c(NA)] <- 0


dta110$HEALTH <- NA
dta110$HEALTH[dta110$QD2=="Excellent"] <- 5
dta110$HEALTH[dta110$QD2=="Very good"] <- 4
dta110$HEALTH[dta110$QD2=="Good"] <- 3
dta110$HEALTH[dta110$QD2=="Only fair"] <- 2
dta110$HEALTH[dta110$QD2=="Poor"] <- 1

#dta110$HEALTH <- NA

dta110$SAWAD <- NA
dta110$SAWADPOS <- NA
dta110$SAWADNEG <- NA
dta110$SAWADBOTH <- NA

dta110$SSTATE <- dta110$STATE

dta110$MALE <- 1*(dta110$QD1=="Male")

dta110$NUMBER <- 110

dta110$MARKET <- NA

dta110$MONTH <- 40

dta110$SELFINSURE <- 0
dta110$SELFINSURE[dta110$QD4A=="Plan you purchased yourself"]<-1

dta110$EMPLINSURE <- 0
dta110$EMPLINSURE[dta110$QD4A=="Plan through your/your spouse's employer"]<-1

dta110$PREEXIST <- NA

#sort(table(dta110$Q2CD[dta110$FAVOR==1]))/sum(sort(table(dta110$Q2CD[dta110$FAVOR==1])))

#lout110a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta110)
#summary(#lout110a)
##mf110a <- model.frame(#lout110a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf110a2 <- subsetn(dta110,select=nms)

#lout110b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta110)
#summary(#lout110b)
##mf110b <- model.frame(#lout110b)

#lout110d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta110)
#summary(#lout110d)
##fv110d <- model.frame(#lout110d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv110a2 <- subsetn(dta110,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s110 <- subsetn(dta110,select=masterlist, subset=T)



####### April 2012
dta109 <- read.por.upper("hni109.por",to.data.frame=T)


dta109$INCOME <- NA
dta109$INCOME[dta109$QD14=="Less than $20,000"] <- 10
dta109$INCOME[dta109$QD14=="$20,000 to less than $30,000"] <- 25
dta109$INCOME[dta109$QD14=="$30,000 to less than $40,000"] <- 35
dta109$INCOME[dta109$QD14=="$40,000 to less than $50,000"] <- 45
dta109$INCOME[dta109$QD14=="$50,000 to less than $75,000"] <- 62.5
dta109$INCOME[dta109$QD14=="$75,000 to less than $90,000"] <- 82.5
dta109$INCOME[dta109$QD14=="$90,000 to less than $100,000"] <- 95
dta109$INCOME[dta109$QD14=="$100,000 or more"] <- 200

dta109$HISP <- (dta109$QD12=="Yes")*1

dta109$EDUC <- NA
dta109$EDUC[dta109$QD11=="None, or grade 1-8"] <- 6
dta109$EDUC[dta109$QD11=="High school incomplete (grades 9-11)"] <- 10
dta109$EDUC[dta109$QD11=="High school graduate (grade 12 or GED certificate)"] <- 12
dta109$EDUC[dta109$QD11=="Technical, trade or vocational school AFTER high school"] <- 13
dta109$EDUC[dta109$QD11=="Some college, no four-year degree (includes associate degree)"] <- 14
dta109$EDUC[dta109$QD11=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta109$EDUC[dta109$QD11=="Post-graduate or professional schooling after college"] <- 19

dta109$PID <- NA
dta109$PID[dta109$QD8=="Democrat"] <- 1
dta109$PID[dta109$QD8 %in% c("Independent","Or what?")] <- 2
dta109$PID[dta109$QD8=="Republican"] <- 3

dta109$PID5 <- NA
dta109$PID5[dta109$PID==1] <- 1
dta109$PID5[dta109$QD8A=="Democratic"] <- 2
dta109$PID5[dta109$QD8A %in% c("Independent/don't lean to either party (VOL.)", "Other party (VOL.)", "(DO NOT READ) Don't know/Refused")] <- 3
dta109$PID5[dta109$QD8A=="Republican"] <- 4
dta109$PID5[dta109$PID==3] <- 5

dta109$REGISTERED <- NA
dta109$REGISTERED[dta109$QD9=="Yes"] <- 1
dta109$REGISTERED[dta109$QD9=="No"] <- 2

dta109$BETPER <- NA
dta109$BETPER[dta109$Q2A=="Better off"] <- 3
dta109$BETPER[dta109$Q2A=="It won't make much difference"] <- 2
dta109$BETPER[dta109$Q2A=="(DO NOT READ) Don't know/Refused"] <- 2
dta109$BETPER[dta109$Q2A=="Worse off"] <- 1

dta109$BETCOU <- NA
dta109$BETCOU[dta109$Q2B=="Better off"] <- 3
dta109$BETCOU[dta109$Q2B=="It won't make much difference"] <- 2
dta109$BETCOU[dta109$Q2B=="(DO NOT READ) Don't know/Refused"] <- 2
dta109$BETCOU[dta109$Q2B=="Worse off"] <- 1

dta109$SUPPORT <- NA
#dta109$SUPPORT[dta109$Q1=="Strongly support"] <- 4
#dta109$SUPPORT[dta109$Q1=="Somewhat support"] <- 3
#dta109$SUPPORT[dta109$Q1=="Somewhat oppose"] <- 2
#dta109$SUPPORT[dta109$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta109$BLACK <- (dta109$QD13=="Black or African-American")*1
dta109$ASIAN <- (dta109$QD13=="Asian")*1
dta109$OTHER <- (dta109$QD13=="Other or mixed race (SPECIFY)")*1

dta109$AGE <- dta109$AGE
dta109$AGE[dta109$AGE==99] <- NA
dta109$MEDICARE <- (dta109$AGE > 64)*1

#dta79$PREEXIST <- (dta79$QD8A=="Yes")*1
dta109$COVERED <- (dta109$QD4=="Covered by health insurance")*1
#dta109$HEALTHNOW <- 1*(dta109$Q1=="It is more important than ever to take on health care reform now")

dta109$IDEO <- NA
dta109$IDEO[dta109$QD8B=="Liberal"] <- 3
dta109$IDEO[dta109$QD8B=="Moderate"] <- 2
dta109$IDEO[dta109$QD8B=="Conservative"] <- 1

dta109$FAVOR <- NA
dta109$FAVOR[dta109$Q1=="Very favorable"] <- 4
dta109$FAVOR[dta109$Q1=="Somewhat favorable"] <- 3
dta109$FAVOR[dta109$Q1=="Somewhat unfavorable"] <- 2
dta109$FAVOR[dta109$Q1=="Very unfavorable"] <- 1

dta109$SELFEMPLOY <- NA
#dta109$SELFEMPLOY[dta109$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta109$RETIRED <- 0
dta109$RETIRED[dta109$QD3=="Retired"] <- 1

dta109$MEDICARESR <- 0
dta109$MEDICARESR <- 1*(dta109$QD4A=="Medicare")
dta109$MEDICARESR[dta109$QD4A %in% c(NA)] <- 0

dta109$MEDICAID <- 0
dta109$MEDICAID <- 1*(dta109$QD4A=="Medicaid/Medi-CAL")
dta109$MEDICAID[dta109$QD4A %in% c(NA)] <- 0

dta109$HEALTH <- NA
#dta109$HEALTH[dta109$QD2=="Excellent"] <- 5
#dta109$HEALTH[dta109$QD2=="Very good"] <- 4
#dta109$HEALTH[dta109$QD2=="Good"] <- 3
#dta109$HEALTH[dta109$QD2=="Only fair"] <- 2
#dta109$HEALTH[dta109$QD2=="Poor"] <- 1

#dta109$HEALTH <- NA

dta109$SAWAD <- NA
dta109$SAWADPOS <- NA
dta109$SAWADNEG <- NA
dta109$SAWADBOTH <- NA

dta109$SSTATE <- dta109$STATE

dta109$MALE <- 1*(dta109$QD1=="Male")

dta109$NUMBER <- 109

dta109$MARKET <- NA

dta109$MONTH <- 39

dta109$SELFINSURE <- 0
dta109$SELFINSURE[dta109$QD4A=="Plan you purchased yourself"]<-1

dta109$EMPLINSURE <- 0
dta109$EMPLINSURE[dta109$QD4A=="Plan through your/your spouse's employer"]<-1

dta109$PREEXIST <- NA

#sort(table(dta109$Q2CD[dta109$FAVOR==1]))/sum(sort(table(dta109$Q2CD[dta109$FAVOR==1])))

#lout109a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta109)
#summary(#lout109a)
##mf109a <- model.frame(#lout109a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf109a2 <- subsetn(dta109,select=nms)

#lout109b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta109)
#summary(#lout109b)
##mf109b <- model.frame(#lout109b)

#lout109d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta109)
#summary(#lout109d)
##fv109d <- model.frame(#lout109d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv109a2 <- subsetn(dta109,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s109 <- subsetn(dta109,select=masterlist, subset=T)


####### March 2012
dta108 <- read.por.upper("hni108.por",to.data.frame=T)

dta108$INCOME <- NA
dta108$INCOME[dta108$QD14=="Less than $20,000"] <- 10
dta108$INCOME[dta108$QD14=="$20,000 to less than $30,000"] <- 25
dta108$INCOME[dta108$QD14=="$30,000 to less than $40,000"] <- 35
dta108$INCOME[dta108$QD14=="$40,000 to less than $50,000"] <- 45
dta108$INCOME[dta108$QD14=="$50,000 to less than $75,000"] <- 62.5
dta108$INCOME[dta108$QD14=="$75,000 to less than $90,000"] <- 82.5
dta108$INCOME[dta108$QD14=="$90,000 to less than $100,000"] <- 95
dta108$INCOME[dta108$QD14=="$100,000 or more"] <- 200

dta108$HISP <- (dta108$QD12=="Yes")*1

dta108$EDUC <- NA
dta108$EDUC[dta108$QD11=="None, or grade 1-8"] <- 6
dta108$EDUC[dta108$QD11=="High school incomplete (grades 9-11)"] <- 10
dta108$EDUC[dta108$QD11=="High school graduate (grade 12 or GED certificate)"] <- 12
dta108$EDUC[dta108$QD11=="Technical, trade or vocational school AFTER high school"] <- 13
dta108$EDUC[dta108$QD11=="Some college, no four-year degree (includes associate degree)"] <- 14
dta108$EDUC[dta108$QD11=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta108$EDUC[dta108$QD11=="Post-graduate or professional schooling after college"] <- 19

dta108$PID <- NA
dta108$PID[dta108$QD8=="Democrat"] <- 1
dta108$PID[dta108$QD8 %in% c("Independent","Or what?")] <- 2
dta108$PID[dta108$QD8=="Republican"] <- 3

dta108$PID5 <- NA
dta108$PID5[dta108$PID==1] <- 1
dta108$PID5[dta108$QD8A=="Democratic"] <- 2
dta108$PID5[dta108$QD8A %in% c("Independent/don't lean to either party (VOL.)", "Other party (VOL.)", "(DO NOT READ) Don't know/Refused")] <- 3
dta108$PID5[dta108$QD8A=="Republican"] <- 4
dta108$PID5[dta108$PID==3] <- 5

dta108$REGISTERED <- NA
dta108$REGISTERED[dta108$QD9=="Yes"] <- 1
dta108$REGISTERED[dta108$QD9=="No"] <- 2

dta108$BETPER <- NA
dta108$BETPER[dta108$Q3A=="Better off"] <- 3
dta108$BETPER[dta108$Q3A=="It won't make much difference"] <- 2
dta108$BETPER[dta108$Q3A=="(DO NOT READ) Don't know/Refused"] <- 2
dta108$BETPER[dta108$Q3A=="Worse off"] <- 1

dta108$BETCOU <- NA
dta108$BETCOU[dta108$Q3B=="Better off"] <- 3
dta108$BETCOU[dta108$Q3B=="It won't make much difference"] <- 2
dta108$BETCOU[dta108$Q3B=="(DO NOT READ) Don't know/Refused"] <- 2
dta108$BETCOU[dta108$Q3B=="Worse off"] <- 1

#dta108$SUPPORT <- NA
#dta108$SUPPORT[dta108$Q1=="Strongly support"] <- 4
#dta108$SUPPORT[dta108$Q1=="Somewhat support"] <- 3
#dta108$SUPPORT[dta108$Q1=="Somewhat oppose"] <- 2
#dta108$SUPPORT[dta108$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta108$BLACK <- (dta108$QD13=="Black or African-American")*1
dta108$ASIAN <- (dta108$QD13=="Asian")*1
dta108$OTHER <- (dta108$QD13=="Other or mixed race (SPECIFY)")*1

dta108$AGE <- dta108$QD5
dta108$AGE[dta108$AGE==99] <- NA
dta108$MEDICARE <- (dta108$AGE > 64)*1

dta79$PREEXIST <- (dta79$QD8A=="Yes")*1
dta108$COVERED <- (dta108$QD4=="Covered by health insurance")*1
#dta108$HEALTHNOW <- 1*(dta108$Q1=="It is more important than ever to take on health care reform now")

#dta108$IDEO <- NA
#dta108$IDEO[dta108$QD9=="Liberal"] <- 3
#dta108$IDEO[dta108$QD9=="Moderate"] <- 2
#dta108$IDEO[dta108$QD9=="Conservative"] <- 1

dta108$IDEO <- NA

dta108$FAVOR <- NA
dta108$FAVOR[dta108$Q1=="Very favorable"] <- 4
dta108$FAVOR[dta108$Q1=="Somewhat favorable"] <- 3
dta108$FAVOR[dta108$Q1=="Somewhat unfavorable"] <- 2
dta108$FAVOR[dta108$Q1=="Very unfavorable"] <- 1

#dta108$SELFEMPLOY <- 0
#dta108$SELFEMPLOY[dta108$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta108$RETIRED <- 0
dta108$RETIRED[dta108$QD3=="Retired"] <- 1

dta108$MEDICARESR <- 0
dta108$MEDICARESR <- 1*(dta108$QD4A=="Medicare")
dta108$MEDICARESR[dta108$QD4A %in% c(NA)] <- 0

dta108$MEDICAID <- 0
dta108$MEDICAID <- 1*(dta108$QD4A=="Medicaid/Medi-CAL")
dta108$MEDICAID[dta108$QD4A %in% c(NA)] <- 0

dta108$HEALTH <- NA
#dta108$HEALTH[dta108$QD2=="Excellent"] <- 5
#dta108$HEALTH[dta108$QD2=="Very good"] <- 4
#dta108$HEALTH[dta108$QD2=="Good"] <- 3
#dta108$HEALTH[dta108$QD2=="Only fair"] <- 2
#dta108$HEALTH[dta108$QD2=="Poor"] <- 1

#dta108$HEALTH <- NA

dta108$SAWAD <- NA
dta108$SAWADPOS <- NA
dta108$SAWADNEG <- NA
dta108$SAWADBOTH <- NA

dta108$SSTATE <- dta108$STATE

dta108$MALE <- 1*(dta108$SEX=="Male")

dta108$NUMBER <- 108

dta108$MARKET <- NA

dta108$MONTH <- 38

dta108$SELFINSURE <- 0
dta108$SELFINSURE[dta108$QD4A=="Plan you purchased yourself"]<-1

dta108$EMPLINSURE <- 0
dta108$EMPLINSURE[dta108$QD4A=="Plan through your/your spouse's employer"]<-1

dta108$PREEXIST <- 0
dta108$PREEXIST[dta108$QD4B=="Yes, someone in household has pre-existing condition"]<- 1

#sort(table(dta108$Q2CD[dta108$FAVOR==1]))/sum(sort(table(dta108$Q2CD[dta108$FAVOR==1])))

#lout108a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta108)
#summary(#lout108a)
##mf108a <- model.frame(#lout108a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf108a2 <- subsetn(dta108,select=nms)

#lout108b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta108)
#summary(#lout108b)
##mf108b <- model.frame(#lout108b)

#lout108d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta108)
#summary(#lout108d)
##fv108d <- model.frame(#lout108d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv108a2 <- subsetn(dta108,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s108 <- subsetn(dta108,select=masterlist, subset=T)


###### february 2012
dta107 <- read.por.upper("hni107.por",to.data.frame=T)

dta107$INCOME <- NA
dta107$INCOME[dta107$QD14=="Less than $20,000"] <- 10
dta107$INCOME[dta107$QD14=="$20,000 to less than $30,000"] <- 25
dta107$INCOME[dta107$QD14=="$30,000 to less than $40,000"] <- 35
dta107$INCOME[dta107$QD14=="$40,000 to less than $50,000"] <- 45
dta107$INCOME[dta107$QD14=="$50,000 to less than $75,000"] <- 62.5
dta107$INCOME[dta107$QD14=="$75,000 to less than $90,000"] <- 82.5
dta107$INCOME[dta107$QD14=="$90,000 to less than $100,000"] <- 95
dta107$INCOME[dta107$QD14=="$100,000 or more"] <- 200

dta107$HISP <- (dta107$QD12=="Yes")*1

dta107$EDUC <- NA
dta107$EDUC[dta107$QD11=="None, or grade 1-8"] <- 6
dta107$EDUC[dta107$QD11=="High school incomplete (grades 9-11)"] <- 10
dta107$EDUC[dta107$QD11=="High school graduate (grade 12 or GED certificate)"] <- 12
dta107$EDUC[dta107$QD11=="Technical, trade or vocational school AFTER high school"] <- 13
dta107$EDUC[dta107$QD11=="Some college, no four-year degree (includes associate degree)"] <- 14
dta107$EDUC[dta107$QD11=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta107$EDUC[dta107$QD11=="Post-graduate or professional schooling after college"] <- 19

dta107$PID <- NA
dta107$PID[dta107$QD8=="Democrat"] <- 1
dta107$PID[dta107$QD8 %in% c("Independent","Or what?")] <- 2
dta107$PID[dta107$QD8=="Republican"] <- 3

dta107$PID5 <- NA
dta107$PID5[dta107$PID==1] <- 1
dta107$PID5[dta107$QD8A=="Democratic"] <- 2
dta107$PID5[dta107$QD8A %in% c("Independent/don't lean to either party (VOL.)", "Other party (VOL.)", "(DO NOT READ) Don't know/Refused")] <- 3
dta107$PID5[dta107$QD8A=="Republican"] <- 4
dta107$PID5[dta107$PID==3] <- 5

dta107$REGISTERED <- NA
dta107$REGISTERED[dta107$QD9=="Yes"] <- 1
dta107$REGISTERED[dta107$QD9=="No"] <- 2

dta107$BETPER <- NA
dta107$BETPER[dta107$Q4A=="Better off"] <- 3
dta107$BETPER[dta107$Q4A=="It won't make much difference"] <- 2
dta107$BETPER[dta107$Q4A=="(DO NOT READ) Don't know/Refused"] <- 2
dta107$BETPER[dta107$Q4A=="Worse off"] <- 1

dta107$BETCOU <- NA
dta107$BETCOU[dta107$Q4B=="Better off"] <- 3
dta107$BETCOU[dta107$Q4B=="It won't make much difference"] <- 2
dta107$BETCOU[dta107$Q4B=="(DO NOT READ) Don't know/Refused"] <- 2
dta107$BETCOU[dta107$Q4B=="Worse off"] <- 1

#dta107$SUPPORT <- NA
#dta107$SUPPORT[dta107$Q1=="Strongly support"] <- 4
#dta107$SUPPORT[dta107$Q1=="Somewhat support"] <- 3
#dta107$SUPPORT[dta107$Q1=="Somewhat oppose"] <- 2
#dta107$SUPPORT[dta107$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta107$BLACK <- (dta107$QD13=="Black or African-American")*1
dta107$ASIAN <- (dta107$QD13=="Asian")*1
dta107$OTHER <- (dta107$QD13=="Other or mixed race (SPECIFY)")*1

#dta107$AGE <- dta107$QD5
dta107$AGE[dta107$AGE==99] <- NA
dta107$MEDICARE <- (dta107$AGE > 64)*1

#dta79$PREEXIST <- (dta79$QD8A=="Yes")*1
dta107$COVERED <- (dta107$QD4=="Covered by health insurance")*1
#dta107$HEALTHNOW <- 1*(dta107$Q1=="It is more important than ever to take on health care reform now")

#dta107$IDEO <- NA
#dta107$IDEO[dta107$QD9=="Liberal"] <- 3
#dta107$IDEO[dta107$QD9=="Moderate"] <- 2
#dta107$IDEO[dta107$QD9=="Conservative"] <- 1

dta107$IDEO <- NA

dta107$FAVOR <- NA
dta107$FAVOR[dta107$Q3=="Very favorable"] <- 4
dta107$FAVOR[dta107$Q3=="Somewhat favorable"] <- 3
dta107$FAVOR[dta107$Q3=="Somewhat unfavorable"] <- 2
dta107$FAVOR[dta107$Q3=="Very unfavorable"] <- 1

#dta107$SELFEMPLOY <- 0
#dta107$SELFEMPLOY[dta107$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta107$RETIRED <- 0
dta107$RETIRED[dta107$QD3=="Retired"] <- 1

dta107$MEDICARESR <- 0
dta107$MEDICARESR <- 1*(dta107$QD4A=="Medicare")
dta107$MEDICARESR[dta107$QD4A %in% c(NA)] <- 0

dta107$MEDICAID <- 0
dta107$MEDICAID <- 1*(dta107$QD4A=="Medicaid/Medi-CAL")
dta107$MEDICAID[dta107$QD4A %in% c(NA)] <- 0

dta107$HEALTH <- NA
dta107$HEALTH[dta107$QD2=="Excellent"] <- 5
dta107$HEALTH[dta107$QD2=="Very good"] <- 4
dta107$HEALTH[dta107$QD2=="Good"] <- 3
dta107$HEALTH[dta107$QD2=="Only fair"] <- 2
dta107$HEALTH[dta107$QD2=="Poor"] <- 1

#dta107$HEALTH <- NA

dta107$SAWAD <- NA
dta107$SAWADPOS <- NA
dta107$SAWADNEG <- NA
dta107$SAWADBOTH <- NA

dta107$SSTATE <- dta107$STATE

dta107$MALE <- 1*(dta107$SEX=="Male")

dta107$NUMBER <- 107

dta107$MARKET <- NA

dta107$MONTH <- 37

dta107$SELFINSURE <- 0
dta107$SELFINSURE[dta107$QD4A=="Plan you purchased yourself"]<-1

dta107$EMPLINSURE <- 0
dta107$EMPLINSURE[dta107$QD4A=="Plan through your/your spouse's employer"]<-1

dta107$PREEXIST <- NA

#sort(table(dta107$Q2CD[dta107$FAVOR==1]))/sum(sort(table(dta107$Q2CD[dta107$FAVOR==1])))

#lout107a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta107)
#summary(#lout107a)
##mf107a <- model.frame(#lout107a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf107a2 <- subsetn(dta107,select=nms)

#lout107b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta107)
#summary(#lout107b)
##mf107b <- model.frame(#lout107b)

#lout107d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta107)
#summary(#lout107d)
##fv107d <- model.frame(#lout107d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv107a2 <- subsetn(dta107,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s107 <- subsetn(dta107,select=masterlist, subset=T)


###### january 2012
dta106 <- read.por.upper("hni106.por",to.data.frame=T)

dta106$INCOME <- NA
dta106$INCOME[dta106$QD14=="Less than $20,000"] <- 10
dta106$INCOME[dta106$QD14=="$20,000 to less than $30,000"] <- 25
dta106$INCOME[dta106$QD14=="$30,000 to less than $40,000"] <- 35
dta106$INCOME[dta106$QD14=="$40,000 to less than $50,000"] <- 45
dta106$INCOME[dta106$QD14=="$50,000 to less than $75,000"] <- 62.5
dta106$INCOME[dta106$QD14=="$75,000 to less than $90,000"] <- 82.5
dta106$INCOME[dta106$QD14=="$90,000 to less than $100,000"] <- 95
dta106$INCOME[dta106$QD14=="$100,000 or more"] <- 200

dta106$HISP <- (dta106$QD12=="Yes")*1

dta106$EDUC <- NA
dta106$EDUC[dta106$QD11=="None, or grade 1-8"] <- 6
dta106$EDUC[dta106$QD11=="High school incomplete (grades 9-11)"] <- 10
dta106$EDUC[dta106$QD11=="High school graduate (grade 12 or GED certificate)"] <- 12
dta106$EDUC[dta106$QD11=="Technical, trade or vocational school AFTER high school"] <- 13
dta106$EDUC[dta106$QD11=="Some college, no four-year degree (includes associate degree)"] <- 14
dta106$EDUC[dta106$QD11=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta106$EDUC[dta106$QD11=="Post-graduate or professional schooling after college"] <- 19

dta106$PID <- NA
dta106$PID[dta106$QD8=="Democrat"] <- 1
dta106$PID[dta106$QD8 %in% c("Independent","Or what?")] <- 2
dta106$PID[dta106$QD8=="Republican"] <- 3

dta106$PID5 <- NA
dta106$PID5[dta106$PID==1] <- 1
dta106$PID5[dta106$QD8A=="Democratic"] <- 2
dta106$PID5[dta106$QD8A %in% c("Independent/don't lean to either party (VOL.)", "Other party (VOL.)", "(DO NOT READ) Don't know/Refused")] <- 3
dta106$PID5[dta106$QD8A=="Republican"] <- 4
dta106$PID5[dta106$PID==3] <- 5

dta106$REGISTERED <- NA
dta106$REGISTERED[dta106$QD9=="Yes"] <- 1
dta106$REGISTERED[dta106$QD9=="No"] <- 2

dta106$BETPER <- NA
dta106$BETPER[dta106$Q2A=="Better off"] <- 3
dta106$BETPER[dta106$Q2A=="It won't make much difference"] <- 2
dta106$BETPER[dta106$Q2A=="(DO NOT READ) Don't know/Refused"] <- 2
dta106$BETPER[dta106$Q2A=="Worse off"] <- 1

dta106$BETCOU <- NA
dta106$BETCOU[dta106$Q2B=="Better off"] <- 3
dta106$BETCOU[dta106$Q2B=="It won't make much difference"] <- 2
dta106$BETCOU[dta106$Q2B=="(DO NOT READ) Don't know/Refused"] <- 2
dta106$BETCOU[dta106$Q2B=="Worse off"] <- 1

#dta106$SUPPORT <- NA
#dta106$SUPPORT[dta106$Q1=="Strongly support"] <- 4
#dta106$SUPPORT[dta106$Q1=="Somewhat support"] <- 3
#dta106$SUPPORT[dta106$Q1=="Somewhat oppose"] <- 2
#dta106$SUPPORT[dta106$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta106$BLACK <- (dta106$QD13=="Black or African-American")*1
dta106$ASIAN <- (dta106$QD13=="Asian")*1
dta106$OTHER <- (dta106$QD13=="Other or mixed race (SPECIFY)")*1

#dta106$AGE <- dta106$QD5
dta106$AGE[dta106$AGE==99] <- NA
dta106$MEDICARE <- (dta106$AGE > 64)*1

#dta79$PREEXIST <- (dta79$QD8A=="Yes")*1
dta106$COVERED <- (dta106$QD4=="Covered by health insurance")*1
#dta106$HEALTHNOW <- 1*(dta106$Q1=="It is more important than ever to take on health care reform now")

#dta106$IDEO <- NA
#dta106$IDEO[dta106$QD9=="Liberal"] <- 3
#dta106$IDEO[dta106$QD9=="Moderate"] <- 2
#dta106$IDEO[dta106$QD9=="Conservative"] <- 1

dta106$IDEO <- NA

dta106$FAVOR <- NA
dta106$FAVOR[dta106$Q1=="Very favorable"] <- 4
dta106$FAVOR[dta106$Q1=="Somewhat favorable"] <- 3
dta106$FAVOR[dta106$Q1=="Somewhat unfavorable"] <- 2
dta106$FAVOR[dta106$Q1=="Very unfavorable"] <- 1

#dta106$SELFEMPLOY <- 0
#dta106$SELFEMPLOY[dta106$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta106$RETIRED <- 0
dta106$RETIRED[dta106$QD3=="Retired"] <- 1

dta106$MEDICARESR <- 0
dta106$MEDICARESR <- 1*(dta106$QD4A=="Medicare")
dta106$MEDICARESR[dta106$QD4A %in% c(NA)] <- 0

dta106$MEDICAID <- 0
dta106$MEDICAID <- 1*(dta106$QD4A=="Medicaid/Medi-CAL")
dta106$MEDICAID[dta106$QD4A %in% c(NA)] <- 0

dta106$HEALTH <- NA
dta106$HEALTH[dta106$QD2=="Excellent"] <- 5
dta106$HEALTH[dta106$QD2=="Very good"] <- 4
dta106$HEALTH[dta106$QD2=="Good"] <- 3
dta106$HEALTH[dta106$QD2=="Only fair"] <- 2
dta106$HEALTH[dta106$QD2=="Poor"] <- 1

#dta106$HEALTH <- NA

dta106$SAWAD <- NA
dta106$SAWADPOS <- NA
dta106$SAWADNEG <- NA
dta106$SAWADBOTH <- NA

dta106$SSTATE <- dta106$STATE

dta106$MALE <- 1*(dta106$SEX=="Male")

dta106$NUMBER <- 106

dta106$MARKET <- NA

dta106$MONTH <- 36

dta106$SELFINSURE <- 0
dta106$SELFINSURE[dta106$QD4A=="Plan you purchased yourself"]<-1

dta106$EMPLINSURE <- 0
dta106$EMPLINSURE[dta106$QD4A=="Plan through your/your spouse's employer"]<-1

dta106$PREEXIST <- NA

#sort(table(dta106$Q2CD[dta106$FAVOR==1]))/sum(sort(table(dta106$Q2CD[dta106$FAVOR==1])))

#lout106a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta106)
#summary(#lout106a)
##mf106a <- model.frame(#lout106a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf106a2 <- subsetn(dta106,select=nms)

#lout106b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta106)
#summary(#lout106b)
##mf106b <- model.frame(#lout106b)

#lout106d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta106)
#summary(#lout106d)
##fv106d <- model.frame(#lout106d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv106a2 <- subsetn(dta106,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s106 <- subsetn(dta106,select=masterlist, subset=T)


##### december 2011
dta105 <- read.por.upper("hni105.por",to.data.frame=T)

dta105$INCOME <- NA
dta105$INCOME[dta105$QD14=="Less than $20,000"] <- 10
dta105$INCOME[dta105$QD14=="$20,000 to less than $30,000"] <- 25
dta105$INCOME[dta105$QD14=="$30,000 to less than $40,000"] <- 35
dta105$INCOME[dta105$QD14=="$40,000 to less than $50,000"] <- 45
dta105$INCOME[dta105$QD14=="$50,000 to less than $75,000"] <- 62.5
dta105$INCOME[dta105$QD14=="$75,000 to less than $90,000"] <- 82.5
dta105$INCOME[dta105$QD14=="$90,000 to less than $100,000"] <- 95
dta105$INCOME[dta105$QD14=="$100,000 or more"] <- 200

dta105$HISP <- (dta105$QD12=="Yes")*1

dta105$EDUC <- NA
dta105$EDUC[dta105$QD11=="None, or grade 1-8"] <- 6
dta105$EDUC[dta105$QD11=="High school incomplete (grades 9-11)"] <- 10
dta105$EDUC[dta105$QD11=="High school graduate (grade 12 or GED certificate)"] <- 12
dta105$EDUC[dta105$QD11=="Technical, trade or vocational school AFTER high school"] <- 13
dta105$EDUC[dta105$QD11=="Some college, no four-year degree (includes associate degree)"] <- 14
dta105$EDUC[dta105$QD11=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta105$EDUC[dta105$QD11=="Post-graduate or professional schooling after college"] <- 19

dta105$PID <- NA
dta105$PID[dta105$QD8=="Democrat"] <- 1
dta105$PID[dta105$QD8 %in% c("Independent","Or what?")] <- 2
dta105$PID[dta105$QD8=="Republican"] <- 3

dta105$PID5 <- NA
dta105$PID5[dta105$PID==1] <- 1
dta105$PID5[dta105$QD8A=="Democratic"] <- 2
dta105$PID5[dta105$QD8A %in% c("Independent/don't lean to either party (VOL.)", "Other party (VOL.)", "(DO NOT READ) Don't know/Refused")] <- 3
dta105$PID5[dta105$QD8A=="Republican"] <- 4
dta105$PID5[dta105$PID==3] <- 5

dta105$REGISTERED <- NA
dta105$REGISTERED[dta105$QD9=="Yes"] <- 1
dta105$REGISTERED[dta105$QD9=="No"] <- 2

dta105$BETPER <- NA
dta105$BETPER[dta105$Q2A=="Better off"] <- 3
dta105$BETPER[dta105$Q2A=="It won't make much difference"] <- 2
dta105$BETPER[dta105$Q2A=="(DO NOT READ) Don't know/Refused"] <- 2
dta105$BETPER[dta105$Q2A=="Worse off"] <- 1

dta105$BETCOU <- NA
dta105$BETCOU[dta105$Q2B=="Better off"] <- 3
dta105$BETCOU[dta105$Q2B=="It won't make much difference"] <- 2
dta105$BETCOU[dta105$Q2B=="(DO NOT READ) Don't know/Refused"] <- 2
dta105$BETCOU[dta105$Q2B=="Worse off"] <- 1

#dta105$SUPPORT <- NA
#dta105$SUPPORT[dta105$Q1=="Strongly support"] <- 4
#dta105$SUPPORT[dta105$Q1=="Somewhat support"] <- 3
#dta105$SUPPORT[dta105$Q1=="Somewhat oppose"] <- 2
#dta105$SUPPORT[dta105$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta105$BLACK <- (dta105$QD13=="Black or African-American")*1
dta105$ASIAN <- (dta105$QD13=="Asian")*1
dta105$OTHER <- (dta105$QD13=="Other or mixed race (SPECIFY)")*1

dta105$AGE <- dta105$QD5
dta105$AGE[dta105$AGE==99] <- NA
dta105$MEDICARE <- (dta105$AGE > 64)*1

#dta79$PREEXIST <- (dta79$QD8A=="Yes")*1
dta105$COVERED <- (dta105$QD4=="Covered by health insurance")*1
#dta105$HEALTHNOW <- 1*(dta105$Q1=="It is more important than ever to take on health care reform now")

#dta105$IDEO <- NA
#dta105$IDEO[dta105$QD9=="Liberal"] <- 3
#dta105$IDEO[dta105$QD9=="Moderate"] <- 2
#dta105$IDEO[dta105$QD9=="Conservative"] <- 1

dta105$IDEO <- NA

dta105$FAVOR <- NA
dta105$FAVOR[dta105$Q1=="Very favorable"] <- 4
dta105$FAVOR[dta105$Q1=="Somewhat favorable"] <- 3
dta105$FAVOR[dta105$Q1=="Somewhat unfavorable"] <- 2
dta105$FAVOR[dta105$Q1=="Very unfavorable"] <- 1

#dta105$SELFEMPLOY <- 0
#dta105$SELFEMPLOY[dta105$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta105$RETIRED <- 0
dta105$RETIRED[dta105$QD3=="Retired"] <- 1

dta105$MEDICARESR <- 0
dta105$MEDICARESR <- 1*(dta105$QD4A=="Medicare")
dta105$MEDICARESR[dta105$QD4A %in% c(NA)] <- 0

dta105$MEDICAID <- 0
dta105$MEDICAID <- 1*(dta105$QD4A=="Medicaid/Medi-CAL")
dta105$MEDICAID[dta105$QD4A %in% c(NA)] <- 0

dta105$HEALTH <- NA
dta105$HEALTH[dta105$QD2=="Excellent"] <- 5
dta105$HEALTH[dta105$QD2=="Very good"] <- 4
dta105$HEALTH[dta105$QD2=="Good"] <- 3
dta105$HEALTH[dta105$QD2=="Only fair"] <- 2
dta105$HEALTH[dta105$QD2=="Poor"] <- 1

#dta105$HEALTH <- NA

dta105$SAWAD <- NA
dta105$SAWADPOS <- NA
dta105$SAWADNEG <- NA
dta105$SAWADBOTH <- NA

dta105$SSTATE <- dta105$STATE

dta105$MALE <- 1*(dta105$QD1=="Male")

dta105$NUMBER <- 105

dta105$MARKET <- NA

dta105$MONTH <- 35

dta105$SELFINSURE <- 0
dta105$SELFINSURE[dta105$QD4A=="Plan you purchased yourself"]<-1

dta105$EMPLINSURE <- 0
dta105$EMPLINSURE[dta105$QD4A=="Plan through your/your spouse's employer"]<-1

dta105$PREEXIST <- NA

#sort(table(dta105$Q2CD[dta105$FAVOR==1]))/sum(sort(table(dta105$Q2CD[dta105$FAVOR==1])))

#lout105a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta105)
#summary(#lout105a)
##mf105a <- model.frame(#lout105a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf105a2 <- subsetn(dta105,select=nms)

#lout105b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta105)
#summary(#lout105b)
##mf105b <- model.frame(#lout105b)

#lout105d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta105)
#summary(#lout105d)
##fv105d <- model.frame(#lout105d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv105a2 <- subsetn(dta105,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s105 <- subsetn(dta105,select=masterlist, subset=T)

##### November 2011
dta104 <- read.por.upper("hni104.por",to.data.frame=T)

dta104$INCOME <- NA
dta104$INCOME[dta104$QD14=="Less than $20,000"] <- 10
dta104$INCOME[dta104$QD14=="$20,000 to less than $30,000"] <- 25
dta104$INCOME[dta104$QD14=="$30,000 to less than $40,000"] <- 35
dta104$INCOME[dta104$QD14=="$40,000 to less than $50,000"] <- 45
dta104$INCOME[dta104$QD14=="$50,000 to less than $75,000"] <- 62.5
dta104$INCOME[dta104$QD14=="$75,000 to less than $90,000"] <- 82.5
dta104$INCOME[dta104$QD14=="$90,000 to less than $100,000"] <- 95
dta104$INCOME[dta104$QD14=="$100,000 or more"] <- 200

dta104$HISP <- (dta104$QD12=="Yes")*1

dta104$EDUC <- NA
dta104$EDUC[dta104$QD11=="None, or grade 1-8"] <- 6
dta104$EDUC[dta104$QD11=="High school incomplete (grades 9-11)"] <- 10
dta104$EDUC[dta104$QD11=="High school graduate (grade 12 or GED certificate)"] <- 12
dta104$EDUC[dta104$QD11=="Technical, trade or vocational school AFTER high school"] <- 13
dta104$EDUC[dta104$QD11=="Some college, no four-year degree (includes associate degree)"] <- 14
dta104$EDUC[dta104$QD11=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta104$EDUC[dta104$QD11=="Post-graduate or professional schooling after college"] <- 19

dta104$PID <- NA
dta104$PID[dta104$QD8=="Democrat"] <- 1
dta104$PID[dta104$QD8 %in% c("Independent","Or what?")] <- 2
dta104$PID[dta104$QD8=="Republican"] <- 3

dta104$PID5 <- NA
dta104$PID5[dta104$PID==1] <- 1
dta104$PID5[dta104$QD8A=="Democratic"] <- 2
dta104$PID5[dta104$QD8A %in% c("Independent/don't lean to either party (VOL.)", "Other party (VOL.)", "(DO NOT READ) Don't know/Refused")] <- 3
dta104$PID5[dta104$QD8A=="Republican"] <- 4
dta104$PID5[dta104$PID==3] <- 5

dta104$REGISTERED <- NA
dta104$REGISTERED[dta104$QD9=="Yes"] <- 1
dta104$REGISTERED[dta104$QD9=="No"] <- 2

dta104$BETPER <- NA
dta104$BETPER[dta104$Q4A=="Better off"] <- 3
dta104$BETPER[dta104$Q4A=="It won't make much difference"] <- 2
dta104$BETPER[dta104$Q4A=="(DO NOT READ) Don't know/Refused"] <- 2
dta104$BETPER[dta104$Q4A=="Worse off"] <- 1

dta104$BETCOU <- NA
dta104$BETCOU[dta104$Q4B=="Better off"] <- 3
dta104$BETCOU[dta104$Q4B=="It won't make much difference"] <- 2
dta104$BETCOU[dta104$Q4B=="(DO NOT READ) Don't know/Refused"] <- 2
dta104$BETCOU[dta104$Q4B=="Worse off"] <- 1


#dta104$SUPPORT <- NA
#dta104$SUPPORT[dta104$Q1=="Strongly support"] <- 4
#dta104$SUPPORT[dta104$Q1=="Somewhat support"] <- 3
#dta104$SUPPORT[dta104$Q1=="Somewhat oppose"] <- 2
#dta104$SUPPORT[dta104$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta104$BLACK <- (dta104$QD13=="Black or African-American")*1
dta104$ASIAN <- (dta104$QD13=="Asian")*1
dta104$OTHER <- (dta104$QD13=="Other or mixed race (SPECIFY)")*1

dta104$AGE <- dta104$QD5
dta104$AGE[dta104$AGE==99] <- NA
dta104$MEDICARE <- (dta104$AGE > 64)*1

#dta79$PREEXIST <- (dta79$QD8A=="Yes")*1
dta104$COVERED <- (dta104$QD4=="Covered by health insurance")*1
#dta104$HEALTHNOW <- 1*(dta104$Q1=="It is more important than ever to take on health care reform now")

#dta104$IDEO <- NA
#dta104$IDEO[dta104$QD9=="Liberal"] <- 3
#dta104$IDEO[dta104$QD9=="Moderate"] <- 2
#dta104$IDEO[dta104$QD9=="Conservative"] <- 1

dta104$IDEO <- NA

dta104$FAVOR <- NA
dta104$FAVOR[dta104$Q1=="Very favorable"] <- 4
dta104$FAVOR[dta104$Q1=="Somewhat favorable"] <- 3
dta104$FAVOR[dta104$Q1=="Somewhat unfavorable"] <- 2
dta104$FAVOR[dta104$Q1=="Very unfavorable"] <- 1

#dta104$SELFEMPLOY <- 0
#dta104$SELFEMPLOY[dta104$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta104$RETIRED <- 0
dta104$RETIRED[dta104$QD3=="Retired"] <- 1

dta104$MEDICARESR <- 0
dta104$MEDICARESR <- 1*(dta104$QD4A=="Medicare")
dta104$MEDICARESR[dta104$QD4A %in% c(NA)] <- 0

dta104$MEDICAID <- 0
dta104$MEDICAID <- 1*(dta104$QD4A=="Medicaid/Medi-CAL")
dta104$MEDICAID[dta104$QD4A %in% c(NA)] <- 0

dta104$HEALTH <- NA
dta104$HEALTH[dta104$QD2=="Excellent"] <- 5
dta104$HEALTH[dta104$QD2=="Very good"] <- 4
dta104$HEALTH[dta104$QD2=="Good"] <- 3
dta104$HEALTH[dta104$QD2=="Only fair"] <- 2
dta104$HEALTH[dta104$QD2=="Poor"] <- 1

#dta104$HEALTH <- NA

dta104$SAWAD <- NA
dta104$SAWADPOS <- NA
dta104$SAWADNEG <- NA
dta104$SAWADBOTH <- NA

dta104$SSTATE <- dta104$STATE

dta104$MALE <- 1*(dta104$QD1=="Male")

dta104$NUMBER <- 104

dta104$MARKET <- NA

dta104$MONTH <- 34

dta104$SELFINSURE <- 0
dta104$SELFINSURE[dta104$QD4A=="Plan you purchased yourself"]<-1

dta104$EMPLINSURE <- 0
dta104$EMPLINSURE[dta104$QD4A=="Plan through your/your spouse's employer"]<-1

dta104$PREEXIST <- NA

dta104$RESPID <- dta104$PSRAID

##txdt <- c("RESPID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
##txdt104a2 <- subsetn(dta104,select=#txdt)

#sort(table(dta104$Q2CD[dta104$FAVOR==1]))/sum(sort(table(dta104$Q2CD[dta104$FAVOR==1])))

#lout104a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta104)
#summary(#lout104a)
##mf104a <- model.frame(#lout104a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf104a2 <- subsetn(dta104,select=nms)

#lout104b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta104)
#summary(#lout104b)
##mf104b <- model.frame(#lout104b)

#lout104d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta104)
#summary(#lout104d)
##fv104d <- model.frame(#lout104d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv104a2 <- subsetn(dta104,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s104 <- subsetn(dta104,select=masterlist, subset=T)


#### october 2011
dta103 <- read.por.upper("hni103.por",to.data.frame=T)

dta103$INCOME <- NA
dta103$INCOME[dta103$QD14=="Less than $20,000"] <- 10
dta103$INCOME[dta103$QD14=="$20,000 to less than $30,000"] <- 25
dta103$INCOME[dta103$QD14=="$30,000 to less than $40,000"] <- 35
dta103$INCOME[dta103$QD14=="$40,000 to less than $50,000"] <- 45
dta103$INCOME[dta103$QD14=="$50,000 to less than $75,000"] <- 62.5
dta103$INCOME[dta103$QD14=="$75,000 to less than $90,000"] <- 82.5
dta103$INCOME[dta103$QD14=="$90,000 to less than $100,000"] <- 95
dta103$INCOME[dta103$QD14=="$100,000 or more"] <- 200

dta103$HISP <- (dta103$QD12=="Yes")*1

dta103$EDUC <- NA
dta103$EDUC[dta103$QD11=="None, or grade 1-8"] <- 6
dta103$EDUC[dta103$QD11=="High school incomplete (grades 9-11)"] <- 10
dta103$EDUC[dta103$QD11=="High school graduate (grade 12 or GED certificate)"] <- 12
dta103$EDUC[dta103$QD11=="Technical, trade or vocational school AFTER high school"] <- 13
dta103$EDUC[dta103$QD11=="Some college, no four-year degree (includes associate degree)"] <- 14
dta103$EDUC[dta103$QD11=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta103$EDUC[dta103$QD11=="Post-graduate or professional schooling after college"] <- 19

dta103$PID <- NA
dta103$PID[dta103$QD8=="Democrat"] <- 1
dta103$PID[dta103$QD8 %in% c("Independent","Or what?")] <- 2
dta103$PID[dta103$QD8=="Republican"] <- 3

dta103$PID5 <- NA
dta103$PID5[dta103$PID==1] <- 1
dta103$PID5[dta103$QD8A=="Democratic"] <- 2
dta103$PID5[dta103$QD8A %in% c("Independent/don't lean to either party (VOL.)", "Other party (VOL.)", "(DO NOT READ) Don't know/Refused")] <- 3
dta103$PID5[dta103$QD8A=="Republican"] <- 4
dta103$PID5[dta103$PID==3] <- 5

dta103$REGISTERED <- NA
dta103$REGISTERED[dta103$QD9=="Yes"] <- 1
dta103$REGISTERED[dta103$QD9=="No"] <- 2

dta103$BETPER <- NA
dta103$BETPER[dta103$Q3A=="Better off"] <- 3
dta103$BETPER[dta103$Q3A=="It won't make much difference"] <- 2
dta103$BETPER[dta103$Q3A=="(DO NOT READ) Don't know/Refused"] <- 2
dta103$BETPER[dta103$Q3A=="Worse off"] <- 1

dta103$BETCOU <- NA
dta103$BETCOU[dta103$Q3B=="Better off"] <- 3
dta103$BETCOU[dta103$Q3B=="It won't make much difference"] <- 2
dta103$BETCOU[dta103$Q3B=="(DO NOT READ) Don't know/Refused"] <- 2
dta103$BETCOU[dta103$Q3B=="Worse off"] <- 1


#dta103$SUPPORT <- NA
#dta103$SUPPORT[dta103$Q1=="Strongly support"] <- 4
#dta103$SUPPORT[dta103$Q1=="Somewhat support"] <- 3
#dta103$SUPPORT[dta103$Q1=="Somewhat oppose"] <- 2
#dta103$SUPPORT[dta103$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta103$BLACK <- (dta103$QD13=="Black or African-American")*1
dta103$ASIAN <- (dta103$QD13=="Asian")*1
dta103$OTHER <- (dta103$QD13=="Other or mixed race (SPECIFY)")*1

dta103$AGE <- dta103$QD5
dta103$AGE[dta103$AGE==99] <- NA
dta103$MEDICARE <- (dta103$AGE > 64)*1

#dta79$PREEXIST <- (dta79$QD8A=="Yes")*1
dta103$COVERED <- (dta103$QD4=="Covered by health insurance")*1
#dta103$HEALTHNOW <- 1*(dta103$Q1=="It is more important than ever to take on health care reform now")

#dta103$IDEO <- NA
#dta103$IDEO[dta103$QD9=="Liberal"] <- 3
#dta103$IDEO[dta103$QD9=="Moderate"] <- 2
#dta103$IDEO[dta103$QD9=="Conservative"] <- 1

dta103$IDEO <- NA

dta103$FAVOR <- NA
dta103$FAVOR[dta103$Q2=="Very favorable"] <- 4
dta103$FAVOR[dta103$Q2=="Somewhat favorable"] <- 3
dta103$FAVOR[dta103$Q2=="Somewhat unfavorable"] <- 2
dta103$FAVOR[dta103$Q2=="Very unfavorable"] <- 1

#dta103$SELFEMPLOY <- 0
#dta103$SELFEMPLOY[dta103$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta103$RETIRED <- 0
dta103$RETIRED[dta103$QD3=="Retired"] <- 1

dta103$MEDICARESR <- 0
dta103$MEDICARESR <- 1*(dta103$QD4A=="Medicare")
dta103$MEDICARESR[dta103$QD4A %in% c(NA)] <- 0

dta103$MEDICAID <- 0
dta103$MEDICAID <- 1*(dta103$QD4A=="Medicaid/Medi-CAL")
dta103$MEDICAID[dta103$QD4A %in% c(NA)] <- 0

dta103$HEALTH <- NA
dta103$HEALTH[dta103$QD2=="Excellent"] <- 5
dta103$HEALTH[dta103$QD2=="Very good"] <- 4
dta103$HEALTH[dta103$QD2=="Good"] <- 3
dta103$HEALTH[dta103$QD2=="Only fair"] <- 2
dta103$HEALTH[dta103$QD2=="Poor"] <- 1

#dta103$HEALTH <- NA

dta103$SAWAD <- NA
dta103$SAWADPOS <- NA
dta103$SAWADNEG <- NA
dta103$SAWADBOTH <- NA

dta103$SSTATE <- dta103$STATE

dta103$MALE <- 1*(dta103$QD1=="Male")

dta103$NUMBER <- 103

dta103$MARKET <- NA

dta103$MONTH <- 33

dta103$SELFINSURE <- 0
dta103$SELFINSURE[dta103$QD4A=="Plan you purchased yourself"]<-1

dta103$EMPLINSURE <- 0
dta103$EMPLINSURE[dta103$QD4A=="Plan through your/your spouse's employer"]<-1

dta103$PREEXIST <- NA

#sort(table(dta103$Q2CD[dta103$FAVOR==1]))/sum(sort(table(dta103$Q2CD[dta103$FAVOR==1])))

#lout103a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta103)
#summary(#lout103a)
##mf103a <- model.frame(#lout103a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf103a2 <- subsetn(dta103,select=nms)

#lout103b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta103)
#summary(#lout103b)
##mf103b <- model.frame(#lout103b)

#lout103d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta103)
#summary(#lout103d)
##fv103d <- model.frame(#lout103d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv103a2 <- subsetn(dta103,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s103 <- subsetn(dta103,select=masterlist, subset=T)


##### SEPTEMBER 2011
dta102 <- read.por.upper("hni102.por",to.data.frame=T)

dta102$INCOME <- NA
dta102$INCOME[dta102$QD14=="Less than $20,000"] <- 10
dta102$INCOME[dta102$QD14=="$20,000 to less than $30,000"] <- 25
dta102$INCOME[dta102$QD14=="$30,000 to less than $40,000"] <- 35
dta102$INCOME[dta102$QD14=="$40,000 to less than $50,000"] <- 45
dta102$INCOME[dta102$QD14=="$50,000 to less than $75,000"] <- 62.5
dta102$INCOME[dta102$QD14=="$75,000 to less than $90,000"] <- 82.5
dta102$INCOME[dta102$QD14=="$90,000 to less than $100,000"] <- 95
dta102$INCOME[dta102$QD14=="$100,000 or more"] <- 200

dta102$HISP <- (dta102$QD12=="Yes")*1

dta102$EDUC <- NA
dta102$EDUC[dta102$QD11=="None, or grade 1-8"] <- 6
dta102$EDUC[dta102$QD11=="High school incomplete (grades 9-11)"] <- 10
dta102$EDUC[dta102$QD11=="High school graduate (grade 12 or GED certificate)"] <- 12
dta102$EDUC[dta102$QD11=="Technical, trade or vocational school AFTER high school"] <- 13
dta102$EDUC[dta102$QD11=="Some college, no four-year degree (includes associate degree)"] <- 14
dta102$EDUC[dta102$QD11=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta102$EDUC[dta102$QD11=="Post-graduate or professional schooling after college"] <- 19

dta102$PID <- NA
dta102$PID[dta102$QD8F1=="Democrat"] <- 1
dta102$PID[dta102$QD8F1 %in% c("Independent","Or what?")] <- 2
dta102$PID[dta102$QD8F1=="Republican"] <- 3

dta102$PID[dta102$QD8F2=="Democrat"] <- 1
dta102$PID[dta102$QD8F2 %in% c("Independent","Or what?","(DO NOT READ) No preference","(DO NOT READ) Other party")] <- 2
dta102$PID[dta102$QD8F2=="Republican"] <- 3

dta102$PID5 <- NA
dta102$PID5[dta102$PID==1] <- 1
dta102$PID5[dta102$QD8A=="Democratic"] <- 2
dta102$PID5[dta102$QD8A %in% c("Independent/don't lean to either party (VOL.)", "Other party (VOL.)")] <- 3
dta102$PID5[dta102$QD8A=="Republican"] <- 4
dta102$PID5[dta102$PID==3] <- 5

dta102$REGISTERED <- NA
dta102$REGISTERED[dta102$QD9=="Yes"] <- 1
dta102$REGISTERED[dta102$QD9=="No"] <- 2

dta102$BETPER <- NA
dta102$BETPER[dta102$Q2A=="Better off"] <- 3
dta102$BETPER[dta102$Q2A=="It won't make much difference"] <- 2
dta102$BETPER[dta102$Q2A=="(DO NOT READ) Don't know/Refused"] <- 2
dta102$BETPER[dta102$Q2A=="Worse off"] <- 1

dta102$BETCOU <- NA
dta102$BETCOU[dta102$Q2B=="Better off"] <- 3
dta102$BETCOU[dta102$Q2B=="It won't make much difference"] <- 2
dta102$BETCOU[dta102$Q2B=="(DO NOT READ) Don't know/Refused"] <- 2
dta102$BETCOU[dta102$Q2B=="Worse off"] <- 1


#dta102$SUPPORT <- NA
#dta102$SUPPORT[dta102$Q1=="Strongly support"] <- 4
#dta102$SUPPORT[dta102$Q1=="Somewhat support"] <- 3
#dta102$SUPPORT[dta102$Q1=="Somewhat oppose"] <- 2
#dta102$SUPPORT[dta102$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta102$BLACK <- (dta102$QD13=="Black or African-American")*1
dta102$ASIAN <- (dta102$QD13=="Asian")*1
dta102$OTHER <- (dta102$QD13=="Other or mixed race (SPECIFY)")*1

dta102$AGE <- dta102$QD5
dta102$AGE[dta102$AGE==99] <- NA
dta102$MEDICARE <- (dta102$AGE > 64)*1

#dta79$PREEXIST <- (dta79$QD8A=="Yes")*1
dta102$COVERED <- (dta102$QD4=="Covered by health insurance")*1
#dta102$HEALTHNOW <- 1*(dta102$Q1=="It is more important than ever to take on health care reform now")

#dta102$IDEO <- NA
#dta102$IDEO[dta102$QD9=="Liberal"] <- 3
#dta102$IDEO[dta102$QD9=="Moderate"] <- 2
#dta102$IDEO[dta102$QD9=="Conservative"] <- 1

dta102$IDEO <- NA

dta102$FAVOR <- NA
dta102$FAVOR[dta102$Q1=="Very favorable"] <- 4
dta102$FAVOR[dta102$Q1=="Somewhat favorable"] <- 3
dta102$FAVOR[dta102$Q1=="Somewhat unfavorable"] <- 2
dta102$FAVOR[dta102$Q1=="Very unfavorable"] <- 1

#dta102$SELFEMPLOY <- 0
#dta102$SELFEMPLOY[dta102$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta102$RETIRED <- 0
dta102$RETIRED[dta102$QD3=="Retired"] <- 1

dta102$MEDICARESR <- 0
dta102$MEDICARESR <- 1*(dta102$QD4A=="Medicare")
dta102$MEDICARESR[dta102$QD4A %in% c(NA)] <- 0

dta102$MEDICAID <- 0
dta102$MEDICAID <- 1*(dta102$QD4A=="Medicaid/Medi-CAL")
dta102$MEDICAID[dta102$QD4A %in% c(NA)] <- 0

dta102$HEALTH <- NA
dta102$HEALTH[dta102$QD2=="Excellent"] <- 5
dta102$HEALTH[dta102$QD2=="Very good"] <- 4
dta102$HEALTH[dta102$QD2=="Good"] <- 3
dta102$HEALTH[dta102$QD2=="Only fair"] <- 2
dta102$HEALTH[dta102$QD2=="Poor"] <- 1

#dta102$HEALTH <- NA

dta102$SAWAD <- NA
dta102$SAWADPOS <- NA
dta102$SAWADNEG <- NA
dta102$SAWADBOTH <- NA

dta102$SSTATE <- dta102$STATE

dta102$MALE <- 1*(dta102$SEX=="Male")

dta102$NUMBER <- 102

dta102$MARKET <- NA

dta102$MONTH <- 32

dta102$SELFINSURE <- 0
dta102$SELFINSURE[dta102$QD4A=="Plan you purchased yourself"]<-1

dta102$EMPLINSURE <- 0
dta102$EMPLINSURE[dta102$QD4A=="Plan through your/your spouse's employer"]<-1

dta102$PREEXIST <- 0
dta102$PREEXIST[dta102$Q5=="Yes"] <- 1

#sort(table(dta102$Q2CD[dta102$FAVOR==1]))/sum(sort(table(dta102$Q2CD[dta102$FAVOR==1])))

#lout102a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta102)
#summary(#lout102a)
##mf102a <- model.frame(#lout102a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf102a2 <- subsetn(dta102,select=nms)

#lout102b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta102)
#summary(#lout102b)
##mf102b <- model.frame(#lout102b)

#lout102d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta102)
#summary(#lout102d)
##fv102d <- model.frame(#lout102d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv102a2 <- subsetn(dta102,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s102 <- subsetn(dta102,select=masterlist, subset=T)



####### AUGUST 2011
dta101 <- read.dta("hni101.dta")
colnames(dta101) <- toupper(colnames(dta101))

dta101$DATE <- as.numeric(dta101$DATE)

dta101$INCOME <- NA
dta101$INCOME[dta101$QD14=="less than $20,000"] <- 10
dta101$INCOME[dta101$QD14=="$20,000 to less than $30,000"] <- 25
dta101$INCOME[dta101$QD14=="$30,000 to less than $40,000"] <- 35
dta101$INCOME[dta101$QD14=="$40,000 to less than $50,000"] <- 45
dta101$INCOME[dta101$QD14=="$50,000 to less than $75,000"] <- 62.5
dta101$INCOME[dta101$QD14=="$75,000 to less than $90,000"] <- 82.5
dta101$INCOME[dta101$QD14=="$90,000 to less than $100,000"] <- 95
dta101$INCOME[dta101$QD14=="$100,000 or more"] <- 200

dta101$HISP <- (dta101$QD12=="yes")*1

dta101$EDUC <- NA
dta101$EDUC[dta101$QD11==tolower("None, or grade 1-8")] <- 6
dta101$EDUC[dta101$QD11==tolower("High school incomplete (grades 9-11)")] <- 10
dta101$EDUC[dta101$QD11==tolower("High school graduate (grade 12 or GED certificate)")] <- 12
dta101$EDUC[dta101$QD11==tolower("Technical, trade or vocational school AFTER high school")] <- 13
dta101$EDUC[dta101$QD11==tolower("Some college, no four-year degree (includes associate degree)")] <- 14
dta101$EDUC[dta101$QD11==tolower("College graduate (B.S., B.A., or other four-year degree)")] <- 16
dta101$EDUC[dta101$QD11==tolower("Post-graduate or professional schooling after college")] <- 19

dta101$PID <- NA
dta101$PID[dta101$QD8F1=="democrat"] <- 1
dta101$PID[dta101$QD8F1 %in% c("independent","or what?")] <- 2
dta101$PID[dta101$QD8F1=="republican"] <- 3

dta101$REGISTERED <- NA
dta101$REGISTERED[dta101$QD9=="Yes"] <- 1
dta101$REGISTERED[dta101$QD9=="No"] <- 2

dta101$PID[dta101$QD8F2=="democrat"] <- 1
dta101$PID[dta101$QD8F2 %in% c("independent","or what?")] <- 2
dta101$PID[dta101$QD8F2=="republican"] <- 3

dta101$BETPER <- NA
dta101$BETPER[dta101$Q2A=="better off"] <- 3
dta101$BETPER[dta101$Q2A=="it won't make much difference"] <- 2
dta101$BETPER[dta101$Q2A=="(do not read) don't know/refused"] <- 2
dta101$BETPER[dta101$Q2A=="worse off"] <- 1

dta101$BETCOU <- NA
dta101$BETCOU[dta101$Q2B=="better off"] <- 3
dta101$BETCOU[dta101$Q2B=="it won't make much difference"] <- 2
dta101$BETCOU[dta101$Q2B=="(do not read) don't know/refused"] <- 2
dta101$BETCOU[dta101$Q2B=="worse off"] <- 1

dta101$BLACK <- (dta101$QD13=="black or african-american")*1
dta101$ASIAN <- (dta101$QD13=="asian")*1
dta101$OTHER <- (dta101$QD13=="other or mixed race (specify)")*1

#dta101$AGE <- dta101$QD5
dta101$AGE[dta101$AGE==99] <- NA
dta101$MEDICARE <- (dta101$AGE > 64)*1

#dta79$PREEXIST <- (dta79$QD8A=="Yes")*1
dta101$COVERED <- (dta101$QD4=="covered by health insurance")*1
#dta101$HEALTHNOW <- 1*(dta101$Q1=="It is more important than ever to take on health care reform now")

#dta101$IDEO <- NA
#dta101$IDEO[dta101$QD9=="Liberal"] <- 3
#dta101$IDEO[dta101$QD9=="Moderate"] <- 2
#dta101$IDEO[dta101$QD9=="Conservative"] <- 1

dta101$IDEO <- NA

dta101$FAVOR <- NA
dta101$FAVOR[dta101$Q1=="very favorable"] <- 4
dta101$FAVOR[dta101$Q1=="somewhat favorable"] <- 3
dta101$FAVOR[dta101$Q1=="somewhat unfavorable"] <- 2
dta101$FAVOR[dta101$Q1=="very unfavorable"] <- 1

#dta101$SELFEMPLOY <- 0
#dta101$SELFEMPLOY[dta101$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta101$RETIRED <- 0
dta101$RETIRED[dta101$QD3=="Retired"] <- 1

dta101$MEDICARESR <- 0
dta101$MEDICARESR <- 1*(dta101$QD4A=="medicare")
dta101$MEDICARESR[dta101$QD4A %in% c(NA)] <- 0

dta101$MEDICAID <- 0
dta101$MEDICAID <- 1*(dta101$QD4A=="medicaid/medi-cal")
dta101$MEDICAID[dta101$QD4A %in% c(NA)] <- 0

dta101$HEALTH <- NA
dta101$HEALTH[dta101$QD2=="excellent"] <- 5
dta101$HEALTH[dta101$QD2=="very good"] <- 4
dta101$HEALTH[dta101$QD2=="good"] <- 3
dta101$HEALTH[dta101$QD2=="only fair"] <- 2
dta101$HEALTH[dta101$QD2=="poor"] <- 1

#dta101$HEALTH <- NA

dta101$SAWAD <- NA
dta101$SAWADPOS <- NA
dta101$SAWADNEG <- NA
dta101$SAWADBOTH <- NA

dta101$SSTATE <- dta101$STATE

dta101$MALE <- 1*(dta101$QD1=="male")

dta101$NUMBER <- 101

dta101$MARKET <- NA

dta101$MONTH <- 31

dta101$SELFINSURE <- 0
dta101$SELFINSURE[dta101$QD4A=="plan you purchased yourself"]<-1

dta101$EMPLINSURE <- 0
dta101$EMPLINSURE[dta101$QD4A=="plan through your employer"]<-1
dta101$EMPLINSURE[dta101$QD4A=="plan through your spouse's employer"]<-1

dta101$PREEXIST <- NA

#sort(table(dta101$Q2CD[dta101$FAVOR==1]))/sum(sort(table(dta101$Q2CD[dta101$FAVOR==1])))

#lout101a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta101)
#summary(#lout101a)
##mf101a <- model.frame(#lout101a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf101a2 <- subsetn(dta101,select=nms)

#lout101b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta101)
#summary(#lout101b)
##mf101b <- model.frame(#lout101b)

#lout101d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta101)
#summary(#lout101d)
##fv101d <- model.frame(#lout101d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv101a2 <- subsetn(dta101,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s101 <- subsetn(dta101,select=masterlist, subset=T)


####### JULY 2011
dta100 <- read.por.upper("hni100.por",to.data.frame=T)

dta100$INCOME <- NA
dta100$INCOME[dta100$QD14=="Less than $20,000"] <- 10
dta100$INCOME[dta100$QD14=="$20,000 to less than $30,000"] <- 25
dta100$INCOME[dta100$QD14=="$30,000 to less than $40,000"] <- 35
dta100$INCOME[dta100$QD14=="$40,000 to less than $50,000"] <- 45
dta100$INCOME[dta100$QD14=="$50,000 to less than $75,000"] <- 62.5
dta100$INCOME[dta100$QD14=="$75,000 to less than $90,000"] <- 82.5
dta100$INCOME[dta100$QD14=="$90,000 to less than $100,000"] <- 95
dta100$INCOME[dta100$QD14=="$100,000 or more"] <- 200

dta100$HISP <- (dta100$QD12=="Yes")*1

dta100$EDUC <- NA
dta100$EDUC[dta100$QD11=="None, or grade 1-8"] <- 6
dta100$EDUC[dta100$QD11=="High school incomplete (grades 9-11)"] <- 10
dta100$EDUC[dta100$QD11=="High school graduate (grade 12 or GED certificate)"] <- 12
dta100$EDUC[dta100$QD11=="Technical, trade or vocational school AFTER high school"] <- 13
dta100$EDUC[dta100$QD11=="Some college, no four-year degree (includes associate degree)"] <- 14
dta100$EDUC[dta100$QD11=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta100$EDUC[dta100$QD11=="Post-graduate or professional schooling after college"] <- 19

dta100$PID <- NA
dta100$PID[dta100$QD8F1=="Democrat"] <- 1
dta100$PID[dta100$QD8F1 %in% c("Independent","Or what?")] <- 2
dta100$PID[dta100$QD8F1=="Republican"] <- 3

dta100$REGISTERED <- NA
dta100$REGISTERED[dta100$QD9=="Yes"] <- 1
dta100$REGISTERED[dta100$QD9=="No"] <- 2

dta100$PID[dta100$QD8F2=="Democrat"] <- 1
dta100$PID[dta100$QD8F2 %in% c("Independent","Or what?","(DO NOT READ) No preference","(DO NOT READ) Other party")] <- 2
dta100$PID[dta100$QD8F2=="Republican"] <- 3

dta100$PID5 <- NA
dta100$PID5[dta100$PID==1] <- 1
dta100$PID5[dta100$QD8A=="Democratic"] <- 2
dta100$PID5[dta100$QD8A %in% c("(DO NOT READ) Independent/don't lean to either party", "(DO NOT READ) Other party", "(DO NOT READ) Don't know/Refused")] <- 3
dta100$PID5[dta100$QD8A=="Republican"] <- 4
dta100$PID5[dta100$PID==3] <- 5

### asked of half sample
dta100$BETPER <- NA
dta100$BETPER[dta100$Q6A=="Better"] <- 3
dta100$BETPER[dta100$Q6A=="It will stay about the same"] <- 2
dta100$BETPER[dta100$Q6A=="Don't know/Refused"] <- 2
dta100$BETPER[dta100$Q6A=="Worse"] <- 1

dta100$BETCOU <- NA
dta100$BETCOU[dta100$Q6B=="Better"] <- 3
dta100$BETCOU[dta100$Q6B=="It will stay about the same"] <- 2
dta100$BETCOU[dta100$Q6B=="Don't know/Refused"] <- 2
dta100$BETCOU[dta100$Q6B=="Worse"] <- 1

#dta100$SUPPORT <- NA
#dta100$SUPPORT[dta100$Q1=="Strongly support"] <- 4
#dta100$SUPPORT[dta100$Q1=="Somewhat support"] <- 3
#dta100$SUPPORT[dta100$Q1=="Somewhat oppose"] <- 2
#dta100$SUPPORT[dta100$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta100$BLACK <- (dta100$QD13=="Black or African-American")*1
dta100$ASIAN <- (dta100$QD13=="Asian")*1
dta100$OTHER <- (dta100$QD13=="Other or mixed race (SPECIFY)")*1

#dta100$AGE <- dta100$QD5

#dta100$AGE <- NA
#dta100$AGE[dta100$RECAGE=="18-24"] <- 21
#dta100$AGE[dta100$RECAGE=="25-34"] <- 30
#dta100$AGE[dta100$RECAGE=="35-44"] <- 40
#dta100$AGE[dta100$RECAGE=="45-54"] <- 50
#dta100$AGE[dta100$RECAGE=="55-64"] <- 60
#dta100$AGE[dta100$RECAGE=="65+"] <- 72.5

dta100$AGE[dta100$AGE==99] <- NA
dta100$MEDICARE <- (dta100$AGE > 64)*1

#dta79$PREEXIST <- (dta79$QD8A=="Yes")*1
dta100$COVERED <- (dta100$QD4=="Covered by health insurance")*1
#dta100$HEALTHNOW <- 1*(dta100$Q1=="It is more important than ever to take on health care reform now")

#dta100$IDEO <- NA
#dta100$IDEO[dta100$QD9=="Liberal"] <- 3
#dta100$IDEO[dta100$QD9=="Moderate"] <- 2
#dta100$IDEO[dta100$QD9=="Conservative"] <- 1

dta100$IDEO <- NA

dta100$FAVOR <- NA
dta100$FAVOR[dta100$Q1=="Very favorable"] <- 4
dta100$FAVOR[dta100$Q1=="Somewhat favorable"] <- 3
dta100$FAVOR[dta100$Q1=="Somewhat unfavorable"] <- 2
dta100$FAVOR[dta100$Q1=="Very unfavorable"] <- 1

#dta100$SELFEMPLOY <- 0
#dta100$SELFEMPLOY[dta100$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta100$RETIRED <- 0
dta100$RETIRED[dta100$QD3=="Retired"] <- 1

dta100$MEDICARESR <- 0
dta100$MEDICARESR <- 1*(dta100$QD4A=="Medicare")
dta100$MEDICARESR[dta100$QD4A %in% c(NA)] <- 0

dta100$MEDICAID <- 0
dta100$MEDICAID <- 1*(dta100$QD4A=="Medicaid/Medi-CAL")
dta100$MEDICAID[dta100$QD4A %in% c(NA)] <- 0

dta100$HEALTH <- NA
dta100$HEALTH[dta100$QD2=="Excellent"] <- 5
dta100$HEALTH[dta100$QD2=="Very good"] <- 4
dta100$HEALTH[dta100$QD2=="Good"] <- 3
dta100$HEALTH[dta100$QD2=="Only fair"] <- 2
dta100$HEALTH[dta100$QD2=="Poor"] <- 1

#dta100$HEALTH <- NA

dta100$SAWAD <- NA
dta100$SAWADPOS <- NA
dta100$SAWADNEG <- NA
dta100$SAWADBOTH <- NA

dta100$SSTATE <- dta100$STATE

dta100$MALE <- 1*(dta100$QD1=="Male")

dta100$NUMBER <- 100

dta100$MARKET <- NA

dta100$MONTH <- 30

dta100$SELFINSURE <- 0
dta100$SELFINSURE[dta100$QD4A=="Plan you purchased yourself"]<-1

dta100$EMPLINSURE <- 0
dta100$EMPLINSURE[dta100$QD4A=="Plan through your/your spouse's employer"]<-1

dta100$PREEXIST <- NA

dta100$RESPID <- dta100$PSRAID

#txdt <- c("RESPID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#txdt100a2 <- subsetn(dta100,select=#txdt)

#sort(table(dta100$Q2CD[dta100$FAVOR==1]))/sum(sort(table(dta100$Q2CD[dta100$FAVOR==1])))

#lout100a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta100)
#summary(#lout100a)
##mf100a <- model.frame(#lout100a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf100a2 <- subsetn(dta100,select=nms)

#lout100b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta100)
#summary(#lout100b)
##mf100b <- model.frame(#lout100b)

#lout100d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta100)
#summary(#lout100d)
##fv100d <- model.frame(#lout100d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv100a2 <- subsetn(dta100,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s100 <- subsetn(dta100,select=masterlist, subset=T)


###### june 2011
dta99 <- read.por.upper("hni099.por",to.data.frame=T)

dta99$INCOME <- NA
dta99$INCOME[dta99$QD14=="Less than $20,000"] <- 10
dta99$INCOME[dta99$QD14=="$20,000 to less than $30,000"] <- 25
dta99$INCOME[dta99$QD14=="$30,000 to less than $40,000"] <- 35
dta99$INCOME[dta99$QD14=="$40,000 to less than $50,000"] <- 45
dta99$INCOME[dta99$QD14=="$50,000 to less than $75,000"] <- 62.5
dta99$INCOME[dta99$QD14=="$75,000 to less than $90,000"] <- 82.5
dta99$INCOME[dta99$QD14=="$90,000 to less than $100,000"] <- 95
dta99$INCOME[dta99$QD14=="$100,000 or more"] <- 200

dta99$HISP <- (dta99$QD12=="Yes")*1

dta99$EDUC <- NA
dta99$EDUC[dta99$QD11=="None, or grade 1-8"] <- 6
dta99$EDUC[dta99$QD11=="High school incomplete (grades 9-11)"] <- 10
dta99$EDUC[dta99$QD11=="High school graduate (grade 12 or GED certificate)"] <- 12
dta99$EDUC[dta99$QD11=="Technical, trade or vocational school AFTER high school"] <- 13
dta99$EDUC[dta99$QD11=="Some college, no four-year degree (includes associate degree)"] <- 14
dta99$EDUC[dta99$QD11=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta99$EDUC[dta99$QD11=="Post-graduate or professional schooling after college"] <- 19

dta99$PID <- NA
dta99$PID[dta99$QD8F1=="Democrat"] <- 1
dta99$PID[dta99$QD8F1 %in% c("Independent","Or what?")] <- 2
dta99$PID[dta99$QD8F1=="Republican"] <- 3

dta99$REGISTERED <- NA
dta99$REGISTERED[dta99$QD9=="Yes"] <- 1
dta99$REGISTERED[dta99$QD9=="No"] <- 2

dta99$PID[dta99$QD8F2=="Democrat"] <- 1
dta99$PID[dta99$QD8F2 %in% c("Independent","Or what?","(DO NOT READ) No preference","(DO NOT READ) Other party")] <- 2
dta99$PID[dta99$QD8F2=="Republican"] <- 3

dta99$PID5 <- NA
dta99$PID5[dta99$PID==1] <- 1
dta99$PID5[dta99$QD8A=="Democratic"] <- 2
dta99$PID5[dta99$QD8A %in% c("Independent/don", "Other party (VOL.)", "(DO NOT READ) Don")] <- 3
dta99$PID5[dta99$QD8A=="Republican"] <- 4
dta99$PID5[dta99$PID==3] <- 5

dta99$BETPER <- NA
dta99$BETPER[dta99$Q4A=="Better off"] <- 3
dta99$BETPER[dta99$Q4A=="It won"] <- 2
dta99$BETPER[dta99$Q4A=="(DO NOT READ) Don"] <- 2
dta99$BETPER[dta99$Q4A=="Worse off"] <- 1

dta99$BETCOU <- NA
dta99$BETCOU[dta99$Q4B=="Better off"] <- 3
dta99$BETCOU[dta99$Q4B=="It won"] <- 2
dta99$BETCOU[dta99$Q4B=="(DO NOT READ) Don"] <- 2
dta99$BETCOU[dta99$Q4B=="Worse off"] <- 1

#dta99$SUPPORT <- NA
#dta99$SUPPORT[dta99$Q1=="Strongly support"] <- 4
#dta99$SUPPORT[dta99$Q1=="Somewhat support"] <- 3
#dta99$SUPPORT[dta99$Q1=="Somewhat oppose"] <- 2
#dta99$SUPPORT[dta99$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta99$BLACK <- (dta99$QD13=="Black or African-American")*1
dta99$ASIAN <- (dta99$QD13=="Asian")*1
dta99$OTHER <- (dta99$QD13=="Other or mixed race (SPECIFY)")*1

dta99$AGE <- dta99$QD5
dta99$AGE[dta99$AGE==99] <- NA
dta99$MEDICARE <- (dta99$AGE > 64)*1

#dta79$PREEXIST <- (dta79$QD8A=="Yes")*1
dta99$COVERED <- (dta99$QD4=="Covered by health insurance")*1
#dta99$HEALTHNOW <- 1*(dta99$Q1=="It is more important than ever to take on health care reform now")

#dta99$IDEO <- NA
#dta99$IDEO[dta99$QD9=="Liberal"] <- 3
#dta99$IDEO[dta99$QD9=="Moderate"] <- 2
#dta99$IDEO[dta99$QD9=="Conservative"] <- 1

dta99$IDEO <- NA

dta99$FAVOR <- NA
dta99$FAVOR[dta99$Q3=="Very favorable"] <- 4
dta99$FAVOR[dta99$Q3=="Somewhat favorable"] <- 3
dta99$FAVOR[dta99$Q3=="Somewhat unfavorable"] <- 2
dta99$FAVOR[dta99$Q3=="Very unfavorable"] <- 1

#dta99$SELFEMPLOY <- 0
#dta99$SELFEMPLOY[dta99$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta99$RETIRED <- 0
dta99$RETIRED[dta99$QD3=="Retired"] <- 1

dta99$MEDICARESR <- 0
dta99$MEDICARESR <- 1*(dta99$QD4A=="Medicare")
dta99$MEDICARESR[dta99$QD4A %in% c(NA)] <- 0

dta99$MEDICAID <- 0
dta99$MEDICAID <- 1*(dta99$QD4A=="Medicaid/Medi-CAL")
dta99$MEDICAID[dta99$QD4A %in% c(NA)] <- 0

dta99$HEALTH <- NA
dta99$HEALTH[dta99$QD2=="Excellent"] <- 5
dta99$HEALTH[dta99$QD2=="Very good"] <- 4
dta99$HEALTH[dta99$QD2=="Good"] <- 3
dta99$HEALTH[dta99$QD2=="Only fair"] <- 2
dta99$HEALTH[dta99$QD2=="Poor"] <- 1

#dta99$HEALTH <- NA

dta99$SAWAD <- NA
dta99$SAWADPOS <- NA
dta99$SAWADNEG <- NA
dta99$SAWADBOTH <- NA

dta99$SSTATE <- dta99$STATE

dta99$MALE <- 1*(dta99$QD1=="Male")

dta99$NUMBER <- 99

dta99$MARKET <- NA

dta99$MONTH <- 29

dta99$SELFINSURE <- 0
dta99$SELFINSURE[dta99$QD4A=="Plan you purchased yourself"]<-1

dta99$EMPLINSURE <- 0
dta99$EMPLINSURE[dta99$QD4A=="Plan through your/your spouse"]<-1

dta99$PREEXIST <- NA

#sort(table(dta99$Q2CD[dta99$FAVOR==1]))/sum(sort(table(dta99$Q2CD[dta99$FAVOR==1])))

#lout99a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta99)
#summary(#lout99a)
##mf99a <- model.frame(#lout99a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf99a2 <- subsetn(dta99,select=nms)

#lout99b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta99)
#summary(#lout99b)
##mf99b <- model.frame(#lout99b)

#lout99d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta99)
#summary(#lout99d)
##fv99d <- model.frame(#lout99d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv99a2 <- subsetn(dta99,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s99 <- subsetn(dta99,select=masterlist, subset=T)


###### may 2011
dta98 <- read.csv.lower("hni098.csv")

dta98$INCOME <- NA
dta98$INCOME[dta98$qd14==1] <- 10
dta98$INCOME[dta98$qd14==2] <- 25
dta98$INCOME[dta98$qd14==3] <- 35
dta98$INCOME[dta98$qd14==4] <- 45
dta98$INCOME[dta98$qd14==5] <- 62.5
dta98$INCOME[dta98$qd14==6] <- 82.5
dta98$INCOME[dta98$qd14==7] <- 95
dta98$INCOME[dta98$qd14==8] <- 200

dta98$HISP2 <- dta98$qd12
dta98$HISP <- (dta98$HISP2==1)*1

dta98$EDUC <- NA
dta98$EDUC[dta98$qd11==1] <- 6
dta98$EDUC[dta98$qd11==2] <- 10
dta98$EDUC[dta98$qd11==3] <- 12
dta98$EDUC[dta98$qd11==4] <- 13
dta98$EDUC[dta98$qd11==5] <- 14
dta98$EDUC[dta98$qd11==6] <- 16
dta98$EDUC[dta98$qd11==7] <- 17
dta98$EDUC[dta98$qd11==8] <- 19

dta98$PID <- NA
dta98$PID[dta98$qd8tot==2] <- 1
dta98$PID[dta98$qd8tot>=3 & dta98$qd8tot<=4] <- 2
dta98$PID[dta98$qd8tot==1] <- 3

# if you use capital letters where you're not supposed to, it won't work!!!
dta98$PID5 <- NA
dta98$PID5[dta98$PID==1] <- 1
dta98$PID5[dta98$qd8a==2] <- 2
dta98$PID5[dta98$qd8a %in% c(3, 4, 9)] <- 3
dta98$PID5[dta98$qd8a==1] <- 4
dta98$PID5[dta98$PID==3] <- 5

dta98$REGISTERED <- NA
dta98$REGISTERED[dta98$QD9=="Yes"] <- 1
dta98$REGISTERED[dta98$QD9=="No"] <- 2

dta98$BETPER <- NA
dta98$BETPER[dta98$q2a==1] <- 3
dta98$BETPER[dta98$q2a==3] <- 2
dta98$BETPER[dta98$q2a==9] <- 2
dta98$BETPER[dta98$q2a==2] <- 1

dta98$BETCOU <- NA
dta98$BETCOU[dta98$q2b==1] <- 3
dta98$BETCOU[dta98$q2b==3] <- 2
dta98$BETCOU[dta98$q2b==9] <- 2
dta98$BETCOU[dta98$q2b==2] <- 1

# NOTE: var replaced with FAVOR var.
dta98$SUPPORT <- NA
#dta98$SUPPORT[dta98$Q1=="Strongly support"] <- 4
#dta98$SUPPORT[dta98$Q1=="Somewhat support"] <- 3
#dta98$SUPPORT[dta98$Q1=="Somewhat oppose"] <- 2
#dta98$SUPPORT[dta98$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta98$BLACK <- (dta98$qd13==2)*1
dta98$ASIAN <- (dta98$qd13==3)*1
dta98$OTHER <- (dta98$qd13==4)*1

dta98$AGE <- dta98$qd5
dta98$AGE[dta98$AGE==99] <- NA
dta98$MEDICARE <- (dta98$AGE > 64)*1

dta98$COVERED <- (dta98$qd4==1)*1

dta98$IDEO <- NA

dta98$FAVOR <- NA
dta98$FAVOR[dta98$q1==1] <- 4
dta98$FAVOR[dta98$q1==2] <- 3
dta98$FAVOR[dta98$q1==3] <- 2
dta98$FAVOR[dta98$q1==4] <- 1

# Question Still Not Asked
dta98$SELFEMPLOY <- NA
#dta98$SELFEMPLOY[dta98$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta98$RETIRED <- 0
dta98$RETIRED[dta98$qd3==6] <- 1

dta98$MEDICARESR <- 0
dta98$MEDICARESR <- 1*(dta98$qd4a==3)
dta98$MEDICARESR[dta98$COVERED==0] <- 0

dta98$MEDICAID <- 0
dta98$MEDICAID <- 1*(dta98$qd4a==4)
dta98$MEDICAID[dta98$COVERED==0] <- 0

dta98$HEALTH <- NA
dta98$HEALTH[dta98$qd2==1] <- 5
dta98$HEALTH[dta98$qd2==2] <- 4
dta98$HEALTH[dta98$qd2==3] <- 3
dta98$HEALTH[dta98$qd2==4] <- 2
dta98$HEALTH[dta98$qd2==5] <- 1

dta98$SAWAD <- NA
dta98$SAWADPOS <- NA
dta98$SAWADNEG <- NA
dta98$SAWADBOTH <- NA

dta98$SSTATE <- dta98$state
dta98$STATE <- dta98$state

dta98$MALE <- 1*(dta98$qd1==1)

dta98$NUMBER <- 98

dta98$MONTH <- 28

dta98$MARKET <- NA

dta98$SELFINSURE <- 0
dta98$SELFINSURE[dta98$qd4a==2]<-1
dta98$SELFINSURE[dta98$COVERED==0] <- 0

dta98$EMPLINSURE <- 0
dta98$EMPLINSURE[dta98$qd4a==1]<-1
dta98$EMPLINSURE[dta98$COVERED==0] <- 0

dta98$PREEXIST <- NA

#sort(table(dta98$Q2CD[dta98$FAVOR==1]))/sum(sort(table(dta98$Q2CD[dta98$FAVOR==1])))

#lout98a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta98)
#summary(#lout98a)
##mf98a <- model.frame(#lout98a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf98a2 <- subsetn(dta98,select=nms)

#lout98b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta98)
#summary(#lout98b)
##mf98b <- model.frame(#lout98b)

#lout98d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta98)
#summary(#lout98d)
##fv98d <- model.frame(#lout98d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv98a2 <- subsetn(dta98,select=fvnms)

dta98$PSRAID <- dta98$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s98 <- subsetn(dta98,select=masterlist, subset=T)


###### april 2011
dta97 <- read.por.upper("hni097.por",to.data.frame=T)

dta97$INCOME <- NA
dta97$INCOME[dta97$QD14=="Less than $20,000"] <- 10
dta97$INCOME[dta97$QD14=="$20,000 to less than $30,000"] <- 25
dta97$INCOME[dta97$QD14=="$30,000 to less than $40,000"] <- 35
dta97$INCOME[dta97$QD14=="$40,000 to less than $50,000"] <- 45
dta97$INCOME[dta97$QD14=="$50,000 to less than $75,000"] <- 62.5
dta97$INCOME[dta97$QD14=="$75,000 to less than $90,000"] <- 82.5
dta97$INCOME[dta97$QD14=="$90,000 to less than $100,000"] <- 95
dta97$INCOME[dta97$QD14=="$100,000 or more"] <- 200

dta97$HISP <- (dta97$QD12=="Yes")*1

dta97$EDUC <- NA
dta97$EDUC[dta97$QD11=="None, or grade 1-8"] <- 6
dta97$EDUC[dta97$QD11=="High school incomplete (grades 9-11)"] <- 10
dta97$EDUC[dta97$QD11=="High school graduate (grade 12 or GED certificate)"] <- 12
dta97$EDUC[dta97$QD11=="Technical, trade or vocational school AFTER high school"] <- 13
dta97$EDUC[dta97$QD11=="Some college, no four-year degree (includes associate degree)"] <- 14
dta97$EDUC[dta97$QD11=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta97$EDUC[dta97$QD11=="Post-graduate or professional schooling after college"] <- 19

dta97$PID <- NA
dta97$PID[dta97$QD8F1=="Democrat"] <- 1
dta97$PID[dta97$QD8F1 %in% c("Independent","Or what?")] <- 2
dta97$PID[dta97$QD8F1=="Republican"] <- 3

dta97$PID[dta97$QD8F2=="Democrat"] <- 1
dta97$PID[dta97$QD8F2 %in% c("Independent","Or what?","(DO NOT READ) No preference","(DO NOT READ) Other party")] <- 2
dta97$PID[dta97$QD8F2=="Republican"] <- 3

dta97$PID5 <- NA
dta97$PID5[dta97$PID==1] <- 1
dta97$PID5[dta97$QD8A=="Democratic"] <- 2
dta97$PID5[dta97$QD8A %in% c("Independent/don", "Other party (VOL.)", "Don")] <- 3
dta97$PID5[dta97$QD8A=="Republican"] <- 4
dta97$PID5[dta97$PID==3] <- 5

dta97$REGISTERED <- NA
dta97$REGISTERED[dta97$QD9=="Yes"] <- 1
dta97$REGISTERED[dta97$QD9=="No"] <- 2

#dta97$PID <- NA
#dta97$PID[dta97$QD8A=="Democrat"] <- 1
#dta97$PID[dta97$QD8A %in% c("(VOL.) Independent/don","(VOL.) Other party")] <- 2
#dta97$PID[dta97$QD8A=="Republican"] <- 3

dta97$BETPER <- NA
dta97$BETPER[dta97$Q2A=="Better off"] <- 3
dta97$BETPER[dta97$Q2A=="It won"] <- 2
dta97$BETPER[dta97$Q2A=="Don"] <- 2
dta97$BETPER[dta97$Q2A=="Worse off"] <- 1

dta97$BETCOU <- NA
dta97$BETCOU[dta97$Q2B=="Better off"] <- 3
dta97$BETCOU[dta97$Q2B=="It won"] <- 2
dta97$BETCOU[dta97$Q2B=="Don"] <- 2
dta97$BETCOU[dta97$Q2B=="Worse off"] <- 1

#dta97$SUPPORT <- NA
#dta97$SUPPORT[dta97$Q1=="Strongly support"] <- 4
#dta97$SUPPORT[dta97$Q1=="Somewhat support"] <- 3
#dta97$SUPPORT[dta97$Q1=="Somewhat oppose"] <- 2
#dta97$SUPPORT[dta97$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta97$BLACK <- (dta97$QD13=="Black or African-American")*1
dta97$ASIAN <- (dta97$QD13=="Asian")*1
dta97$OTHER <- (dta97$QD13=="Other or mixed race (SPECIFY)")*1

dta97$AGE <- dta97$QD5
dta97$AGE[dta97$AGE==99] <- NA
dta97$MEDICARE <- (dta97$AGE > 64)*1

#dta79$PREEXIST <- (dta79$QD8A=="Yes")*1
dta97$COVERED <- (dta97$QD4=="Covered by health insurance")*1
#dta97$HEALTHNOW <- 1*(dta97$Q1=="It is more important than ever to take on health care reform now")

#dta97$IDEO <- NA
#dta97$IDEO[dta97$QD9=="Liberal"] <- 3
#dta97$IDEO[dta97$QD9=="Moderate"] <- 2
#dta97$IDEO[dta97$QD9=="Conservative"] <- 1

dta97$IDEO <- NA

dta97$FAVOR <- NA
dta97$FAVOR[dta97$Q1=="Very favorable"] <- 4
dta97$FAVOR[dta97$Q1=="Somewhat favorable"] <- 3
dta97$FAVOR[dta97$Q1=="Somewhat unfavorable"] <- 2
dta97$FAVOR[dta97$Q1=="Very unfavorable"] <- 1

#dta97$SELFEMPLOY <- 0
#dta97$SELFEMPLOY[dta97$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta97$RETIRED <- 0
dta97$RETIRED[dta97$QD3=="Retired"] <- 1

dta97$MEDICARESR <- 0
dta97$MEDICARESR <- 1*(dta97$QD4A=="Medicare")
dta97$MEDICARESR[dta97$QD4A %in% c(NA)] <- 0

dta97$MEDICAID <- 0
dta97$MEDICAID <- 1*(dta97$QD4A=="Medicaid/Medi-CAL")
dta97$MEDICAID[dta97$QD4A %in% c(NA)] <- 0

dta97$HEALTH <- NA
dta97$HEALTH[dta97$QD2=="Excellent"] <- 5
dta97$HEALTH[dta97$QD2=="Very good"] <- 4
dta97$HEALTH[dta97$QD2=="Good"] <- 3
dta97$HEALTH[dta97$QD2=="Only fair"] <- 2
dta97$HEALTH[dta97$QD2=="Poor"] <- 1

#dta97$HEALTH <- NA

dta97$SAWAD <- NA
dta97$SAWADPOS <- NA
dta97$SAWADNEG <- NA
dta97$SAWADBOTH <- NA

dta97$SSTATE <- dta97$STATE

dta97$MALE <- 1*(dta97$QD1=="Male")

dta97$NUMBER <- 97

dta97$MARKET <- NA

dta97$MONTH <- 27

dta97$SELFINSURE <- 0
dta97$SELFINSURE[dta97$QD4A=="Plan you purchased yourself"]<-1

dta97$EMPLINSURE <- 0
dta97$EMPLINSURE[dta97$QD4A=="Plan through your/your spouse"]<-1

dta97$PREEXIST <- NA

#sort(table(dta97$Q2CD[dta97$FAVOR==1]))/sum(sort(table(dta97$Q2CD[dta97$FAVOR==1])))

#lout97a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta97)
#summary(#lout97a)
##mf97a <- model.frame(#lout97a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf97a2 <- subsetn(dta97,select=nms)

#lout97b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta97)
#summary(#lout97b)
##mf97b <- model.frame(#lout97b)

#lout97d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta97)
#summary(#lout97d)
##fv97d <- model.frame(#lout97d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv97a2 <- subsetn(dta97,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s97 <- subsetn(dta97,select=masterlist, subset=T)


####### march 2011
dta96 <- read.csv.lower("hni096.csv")

dta96$INCOME <- NA
dta96$INCOME[dta96$qd14==1] <- 10
dta96$INCOME[dta96$qd14==2] <- 25
dta96$INCOME[dta96$qd14==3] <- 35
dta96$INCOME[dta96$qd14==4] <- 45
dta96$INCOME[dta96$qd14==5] <- 62.5
dta96$INCOME[dta96$qd14==6] <- 82.5
dta96$INCOME[dta96$qd14==7] <- 95
dta96$INCOME[dta96$qd14==8] <- 200

dta96$HISP2 <- dta96$qd12
dta96$HISP <- (dta96$HISP2==1)*1

dta96$EDUC <- NA
dta96$EDUC[dta96$qd11==1] <- 6
dta96$EDUC[dta96$qd11==2] <- 10
dta96$EDUC[dta96$qd11==3] <- 12
dta96$EDUC[dta96$qd11==4] <- 13
dta96$EDUC[dta96$qd11==5] <- 14
dta96$EDUC[dta96$qd11==6] <- 16
dta96$EDUC[dta96$qd11==7] <- 17
dta96$EDUC[dta96$qd11==8] <- 19

dta96$PID <- NA
dta96$PID[dta96$qd8==2] <- 1
dta96$PID[dta96$qd8>=3 & dta96$qd8<=4] <- 2
dta96$PID[dta96$qd8==1] <- 3

dta96$PID5 <- NA
dta96$PID5[dta96$PID==1] <- 1
dta96$PID5[dta96$qd8a==2] <- 2
dta96$PID5[dta96$qd8a %in% c(3, 4, 9)] <- 3
dta96$PID5[dta96$qd8a==1] <- 4
dta96$PID5[dta96$PID==3] <- 5

dta96$BETPER <- NA
dta96$BETPER[dta96$q3a==1] <- 3
dta96$BETPER[dta96$q3a==3] <- 2
dta96$BETPER[dta96$q3a==9] <- 2
dta96$BETPER[dta96$q3a==2] <- 1

dta96$BETCOU <- NA
dta96$BETCOU[dta96$q3b==1] <- 3
dta96$BETCOU[dta96$q3b==3] <- 2
dta96$BETCOU[dta96$q3b==9] <- 2
dta96$BETCOU[dta96$q3b==2] <- 1

# NOTE: var replaced with FAVOR var.
dta96$SUPPORT <- NA
#dta96$SUPPORT[dta96$Q1=="Strongly support"] <- 4
#dta96$SUPPORT[dta96$Q1=="Somewhat support"] <- 3
#dta96$SUPPORT[dta96$Q1=="Somewhat oppose"] <- 2
#dta96$SUPPORT[dta96$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta96$BLACK <- (dta96$qd13==2)*1
dta96$ASIAN <- (dta96$qd13==3)*1
dta96$OTHER <- (dta96$qd13==4)*1

dta96$AGE <- dta96$qd5
dta96$AGE[dta96$AGE==99] <- NA
dta96$MEDICARE <- (dta96$AGE > 64)*1

dta96$COVERED <- (dta96$qd4==1)*1

dta96$IDEO <- NA

dta96$FAVOR <- NA
dta96$FAVOR[dta96$q1==1] <- 4
dta96$FAVOR[dta96$q1==2] <- 3
dta96$FAVOR[dta96$q1==3] <- 2
dta96$FAVOR[dta96$q1==4] <- 1

# Question Still Not Asked
dta96$SELFEMPLOY <- NA
#dta96$SELFEMPLOY[dta96$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta96$RETIRED <- 0
dta96$RETIRED[dta96$qd3==6] <- 1

dta96$MEDICARESR <- 0
dta96$MEDICARESR <- 1*(dta96$qd4a==3)
dta96$MEDICARESR[dta96$COVERED==0] <- 0

dta96$MEDICAID <- 0
dta96$MEDICAID <- 1*(dta96$qd4a==4)
dta96$MEDICAID[dta96$COVERED==0] <- 0

dta96$HEALTH <- NA
dta96$HEALTH[dta96$qd2==1] <- 5
dta96$HEALTH[dta96$qd2==2] <- 4
dta96$HEALTH[dta96$qd2==3] <- 3
dta96$HEALTH[dta96$qd2==4] <- 2
dta96$HEALTH[dta96$qd2==5] <- 1

dta96$SAWAD <- NA
dta96$SAWADPOS <- NA
dta96$SAWADNEG <- NA
dta96$SAWADBOTH <- NA

dta96$SSTATE <- dta96$state
dta96$STATE <- dta96$state

dta96$MALE <- 1*(dta96$qd1==1)

dta96$NUMBER <- 96

dta96$MONTH <- 26

dta96$MARKET <- NA

dta96$SELFINSURE <- 0
dta96$SELFINSURE[dta96$qd4a==2]<-1
dta96$SELFINSURE[dta96$COVERED==0] <- 0

dta96$EMPLINSURE <- 0
dta96$EMPLINSURE[dta96$qd4a==1]<-1
dta96$EMPLINSURE[dta96$COVERED==0] <- 0

dta96$PREEXIST <- NA

#sort(table(dta96$Q2CD[dta96$FAVOR==1]))/sum(sort(table(dta96$Q2CD[dta96$FAVOR==1])))

#lout96a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta96)
#summary(#lout96a)
##mf96a <- model.frame(#lout96a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf96a2 <- subsetn(dta96,select=nms)

#lout96b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta96)
#summary(#lout96b)
##mf96b <- model.frame(#lout96b)

#lout96d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta96)
#summary(#lout96d)
##fv96d <- model.frame(#lout96d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv96a2 <- subsetn(dta96,select=fvnms)

dta96$PSRAID <- dta96$psraid
dta96$REGISTERED <- NA

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s96 <- subsetn(dta96,select=masterlist, subset=T)


####### february 2011
dta95 <- read.csv.lower("hni095.csv")

dta95$INCOME <- NA
dta95$INCOME[dta95$qd14==1] <- 10
dta95$INCOME[dta95$qd14==2] <- 25
dta95$INCOME[dta95$qd14==3] <- 35
dta95$INCOME[dta95$qd14==4] <- 45
dta95$INCOME[dta95$qd14==5] <- 62.5
dta95$INCOME[dta95$qd14==6] <- 82.5
dta95$INCOME[dta95$qd14==7] <- 95
dta95$INCOME[dta95$qd14==8] <- 200

dta95$HISP2 <- dta95$qd12
dta95$HISP <- (dta95$HISP2==1)*1

dta95$EDUC <- NA
dta95$EDUC[dta95$qd11==1] <- 6
dta95$EDUC[dta95$qd11==2] <- 10
dta95$EDUC[dta95$qd11==3] <- 12
dta95$EDUC[dta95$qd11==4] <- 13
dta95$EDUC[dta95$qd11==5] <- 14
dta95$EDUC[dta95$qd11==6] <- 16
dta95$EDUC[dta95$qd11==7] <- 17
dta95$EDUC[dta95$qd11==8] <- 19

dta95$PID <- NA
dta95$PID[dta95$qd8==2] <- 1
dta95$PID[dta95$qd8>=3 & dta95$qd8<=4] <- 2
dta95$PID[dta95$qd8==1] <- 3

dta95$PID5 <- NA
dta95$PID5[dta95$PID==1] <- 1
dta95$PID5[dta95$qd8a==2] <- 2
dta95$PID5[dta95$qd8a %in% c(3, 4, 9)] <- 3
dta95$PID5[dta95$qd8a==1] <- 4
dta95$PID5[dta95$PID==3] <- 5

dta95$BETPER <- NA
dta95$BETPER[dta95$q3a=="Better off"] <- 3
dta95$BETPER[dta95$q3a=="It won"] <- 2
dta95$BETPER[dta95$q3a=="(DO NOT READ) Don"] <- 2
dta95$BETPER[dta95$q3a=="Worse off"] <- 1

dta95$BETCOU <- NA
dta95$BETCOU[dta95$q3b=="Better off"] <- 3
dta95$BETCOU[dta95$q3b=="It won"] <- 2
dta95$BETCOU[dta95$q3b=="(DO NOT READ) Don"] <- 2
dta95$BETCOU[dta95$q3b=="Worse off"] <- 1

# NOTE: var replaced with FAVOR var.
dta95$SUPPORT <- NA
#dta95$SUPPORT[dta95$Q1=="Strongly support"] <- 4
#dta95$SUPPORT[dta95$Q1=="Somewhat support"] <- 3
#dta95$SUPPORT[dta95$Q1=="Somewhat oppose"] <- 2
#dta95$SUPPORT[dta95$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta95$BLACK <- (dta95$qd13==2)*1
dta95$ASIAN <- (dta95$qd13==3)*1
dta95$OTHER <- (dta95$qd13==4)*1

dta95$AGE <- dta95$age
dta95$AGE[dta95$AGE==99] <- NA
dta95$MEDICARE <- (dta95$AGE > 64)*1

dta95$COVERED <- (dta95$qd4==1)*1

dta95$IDEO <- NA
dta95$IDEO[dta95$qd9==1] <- 3
dta95$IDEO[dta95$qd9==2] <- 2
dta95$IDEO[dta95$qd9==3] <- 1

dta95$FAVOR <- NA
dta95$FAVOR[dta95$q2==1] <- 4
dta95$FAVOR[dta95$q2==2] <- 3
dta95$FAVOR[dta95$q2==3] <- 2
dta95$FAVOR[dta95$q2==4] <- 1

# Question Still Not Asked
dta95$SELFEMPLOY <- NA
#dta95$SELFEMPLOY[dta95$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta95$RETIRED <- 0
dta95$RETIRED[dta95$qd3==4] <- 1

dta95$MEDICARESR <- 0
dta95$MEDICARESR <- 1*(dta95$qd4a==3)
dta95$MEDICARESR[dta95$COVERED==0] <- 0

dta95$MEDICAID <- 0
dta95$MEDICAID <- 1*(dta95$qd4a==4)
dta95$MEDICAID[dta95$COVERED==0] <- 0

dta95$HEALTH <- NA
dta95$HEALTH[dta95$qd2==1] <- 5
dta95$HEALTH[dta95$qd2==2] <- 4
dta95$HEALTH[dta95$qd2==3] <- 3
dta95$HEALTH[dta95$qd2==4] <- 2
dta95$HEALTH[dta95$qd2==5] <- 1

dta95$SAWAD <- NA
dta95$SAWADPOS <- NA
dta95$SAWADNEG <- NA
dta95$SAWADBOTH <- NA

dta95$SSTATE <- dta95$state
dta95$STATE <- dta95$state

dta95$MALE <- 1*(dta95$d1==1)

dta95$NUMBER <- 95

dta95$MONTH <- 25

dta95$MARKET <- NA

dta95$SELFINSURE <- 0
dta95$SELFINSURE[dta95$qd4a==2]<-1
dta95$SELFINSURE[dta95$COVERED==0] <- 0

dta95$EMPLINSURE <- 0
dta95$EMPLINSURE[dta95$qd4a==1]<-1
dta95$EMPLINSURE[dta95$COVERED==0] <- 0

dta95$PREEXIST <- NA

#sort(table(dta95$Q2CD[dta95$FAVOR==1]))/sum(sort(table(dta95$Q2CD[dta95$FAVOR==1])))

#lout95a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta95)
#summary(#lout95a)
##mf95a <- model.frame(#lout95a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf95a2 <- subsetn(dta95,select=nms)

#lout95b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta95)
#summary(#lout95b)
##mf95b <- model.frame(#lout95b)

#lout95d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta95)
#summary(#lout95d)
##fv95d <- model.frame(#lout95d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv95a2 <- subsetn(dta95,select=fvnms)

dta95$PSRAID <- dta95$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s95 <- subsetn(dta95,select=masterlist, subset=T)


####### December 2010
dta94 <- read.por.upper("hni094.por",to.data.frame=T)

dta94$INCOME <- NA
dta94$INCOME[dta94$QD14=="Less than $20,000"] <- 10
dta94$INCOME[dta94$QD14=="$20,000 to less than $30,000"] <- 25
dta94$INCOME[dta94$QD14=="$30,000 to less than $40,000"] <- 35
dta94$INCOME[dta94$QD14=="$40,000 to less than $50,000"] <- 45
dta94$INCOME[dta94$QD14=="$50,000 to less than $75,000"] <- 62.5
dta94$INCOME[dta94$QD14=="$75,000 to less than $90,000"] <- 82.5
dta94$INCOME[dta94$QD14=="$90,000 to less than $100,000"] <- 95
dta94$INCOME[dta94$QD14=="$100,000 or more"] <- 200

dta94$HISP <- (dta94$QD12=="Yes")*1

dta94$EDUC <- NA
dta94$EDUC[dta94$QD11=="None, or grade 1-8"] <- 6
dta94$EDUC[dta94$QD11=="High school incomplete (grades 9-11)"] <- 10
dta94$EDUC[dta94$QD11=="High school graduate (grade 12 or GED certificate)"] <- 12
dta94$EDUC[dta94$QD11=="Technical, trade or vocational school AFTER high school"] <- 13
dta94$EDUC[dta94$QD11=="Some college, no four-year degree (includes associate degree)"] <- 14
dta94$EDUC[dta94$QD11=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta94$EDUC[dta94$QD11=="Post-graduate or professional schooling after college"] <- 19

dta94$PID <- NA
dta94$PID[dta94$QD8=="Democrat"] <- 1
dta94$PID[dta94$QD8 %in% c("Independent","Or what (incl. other/none)")] <- 2
dta94$PID[dta94$QD8=="Republican"] <- 3

#dta94$PID <- NA
#dta94$PID[dta94$QD8A=="Democrat"] <- 1
#dta94$PID[dta94$QD8A %in% c("(VOL.) Independent/don","(VOL.) Other party")] <- 2
#dta94$PID[dta94$QD8A=="Republican"] <- 3

dta94$BETPER <- NA
dta94$BETPER[dta94$Q2A=="Better off"] <- 3
dta94$BETPER[dta94$Q2A=="It won"] <- 2
dta94$BETPER[dta94$Q2A=="(DO NOT READ) Don"] <- 2
dta94$BETPER[dta94$Q2A=="Worse off"] <- 1

dta94$BETCOU <- NA
dta94$BETCOU[dta94$Q2B=="Better off"] <- 3
dta94$BETCOU[dta94$Q2B=="It won"] <- 2
dta94$BETCOU[dta94$Q2B=="(DO NOT READ) Don"] <- 2
dta94$BETCOU[dta94$Q2B=="Worse off"] <- 1

#dta94$SUPPORT <- NA
#dta94$SUPPORT[dta94$Q1=="Strongly support"] <- 4
#dta94$SUPPORT[dta94$Q1=="Somewhat support"] <- 3
#dta94$SUPPORT[dta94$Q1=="Somewhat oppose"] <- 2
#dta94$SUPPORT[dta94$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta94$BLACK <- (dta94$QD13=="Black or African-American")*1
dta94$ASIAN <- (dta94$QD13=="Asian")*1
dta94$OTHER <- (dta94$QD13=="Other or mixed race (SPECIFY)")*1

dta94$AGE <- dta94$QD5
dta94$AGE[dta94$AGE==99] <- NA
dta94$MEDICARE <- (dta94$AGE > 64)*1

#dta79$PREEXIST <- (dta79$QD8A=="Yes")*1
dta94$COVERED <- (dta94$QD4=="Covered by health insurance")*1
#dta94$HEALTHNOW <- 1*(dta94$Q1=="It is more important than ever to take on health care reform now")

#dta94$IDEO <- NA
#dta94$IDEO[dta94$QD9=="Liberal"] <- 3
#dta94$IDEO[dta94$QD9=="Moderate"] <- 2
#dta94$IDEO[dta94$QD9=="Conservative"] <- 1

dta94$IDEO <- NA

dta94$FAVOR <- NA
dta94$FAVOR[dta94$Q1=="Very favorable"] <- 4
dta94$FAVOR[dta94$Q1=="Somewhat favorable"] <- 3
dta94$FAVOR[dta94$Q1=="Somewhat unfavorable"] <- 2
dta94$FAVOR[dta94$Q1=="Very unfavorable"] <- 1

dta94$SELFEMPLOY <- 0
dta94$SELFEMPLOY[dta94$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta94$RETIRED <- 0
dta94$RETIRED[dta94$QD3=="Retired"] <- 1

dta94$MEDICARESR <- 0
dta94$MEDICARESR <- 1*(dta94$QD4A=="Medicare")
dta94$MEDICARESR[dta94$QD4A %in% c(NA)] <- 0

dta94$MEDICAID <- 0
dta94$MEDICAID <- 1*(dta94$QD4A=="Medicaid/Medi-CAL")
dta94$MEDICAID[dta94$QD4A %in% c(NA)] <- 0

dta94$HEALTH <- NA
dta94$HEALTH[dta94$QD2=="Excellent"] <- 5
dta94$HEALTH[dta94$QD2=="Very good"] <- 4
dta94$HEALTH[dta94$QD2=="Good"] <- 3
dta94$HEALTH[dta94$QD2=="Only fair"] <- 2
dta94$HEALTH[dta94$QD2=="Poor"] <- 1

#dta94$HEALTH <- NA

dta94$SAWAD <- NA
dta94$SAWADPOS <- NA
dta94$SAWADNEG <- NA
dta94$SAWADBOTH <- NA

dta94$SSTATE <- dta94$STATE

dta94$MALE <- 1*(dta94$QD1=="Male")

dta94$NUMBER <- 94

dta94$MARKET <- NA

dta94$MONTH <- 23

dta94$SELFINSURE <- 0
dta94$SELFINSURE[dta94$QD4A=="Plan you purchased yourself"]<-1

dta94$EMPLINSURE <- 0
dta94$EMPLINSURE[dta94$QD4A=="Plan through your/your spouse"]<-1

dta94$PREEXIST <- NA

#sort(table(dta94$Q2CD[dta94$FAVOR==1]))/sum(sort(table(dta94$Q2CD[dta94$FAVOR==1])))

#lout94a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta94)
#summary(#lout94a)
##mf94a <- model.frame(#lout94a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf94a2 <- subsetn(dta94,select=nms)

#lout94b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta94)
#summary(#lout94b)
##mf94b <- model.frame(#lout94b)

#lout94d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta94)
#summary(#lout94d)
##fv94d <- model.frame(#lout94d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv94a2 <- subsetn(dta94,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s94 <- subsetn(dta94,select=masterlist, subset=T)


####### November 2010
dta93 <- read.por.upper("hni093.por",to.data.frame=T)

dta93$INCOME <- NA
dta93$INCOME[dta93$QD14=="Less than $20,000"] <- 10
dta93$INCOME[dta93$QD14=="$20,000 to less than $30,000"] <- 25
dta93$INCOME[dta93$QD14=="$30,000 to less than $40,000"] <- 35
dta93$INCOME[dta93$QD14=="$40,000 to less than $50,000"] <- 45
dta93$INCOME[dta93$QD14=="$50,000 to less than $75,000"] <- 62.5
dta93$INCOME[dta93$QD14=="$75,000 to less than $90,000"] <- 82.5
dta93$INCOME[dta93$QD14=="$90,000 to less than $100,000"] <- 95
dta93$INCOME[dta93$QD14=="$100,000 or more"] <- 200

dta93$HISP <- (dta93$QD12=="Yes")*1

dta93$EDUC <- NA
dta93$EDUC[dta93$QD11=="None, or grade 1-8"] <- 6
dta93$EDUC[dta93$QD11=="High school incomplete (grades 9-11)"] <- 10
dta93$EDUC[dta93$QD11=="High school graduate (grade 12 or GED certificate)"] <- 12
dta93$EDUC[dta93$QD11=="Technical, trade or vocational school AFTER high school"] <- 13
dta93$EDUC[dta93$QD11=="Some college, no four-year degree (includes associate degree)"] <- 14
dta93$EDUC[dta93$QD11=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta93$EDUC[dta93$QD11=="Post-graduate or professional schooling after college"] <- 19

dta93$PID <- NA
dta93$PID[dta93$QD8=="Democrat"] <- 1
dta93$PID[dta93$QD8 %in% c("Independent","Or what (incl. other/none)")] <- 2
dta93$PID[dta93$QD8=="Republican"] <- 3

dta93$PID5 <- NA
dta93$PID5[dta93$PID==1] <- 1
dta93$PID5[dta93$QD8A=="Democratic"] <- 2
dta93$PID5[dta93$QD8A %in% c("(DO NOT READ) Independent/don't lean to either party", "(DO NOT READ) Other party", "(DO NOT READ) Don't know/Refused")] <- 3
dta93$PID5[dta93$QD8A=="Republican"] <- 4
dta93$PID5[dta93$PID==3] <- 5

dta93$REGISTERED <- NA
dta93$REGISTERED[dta93$Q1=="Yes"] <- 1
dta93$REGISTERED[dta93$Q1=="No"] <- 2

dta93$VOTED <- NA
dta93$VOTED[dta93$Q2=="Yes, voted"] <- 1
dta93$VOTED[dta93$Q2=="No, did not vote"] <- 2

#dta93$PID <- NA
#dta93$PID[dta93$QD8A=="Democrat"] <- 1
#dta93$PID[dta93$QD8A %in% c("(VOL.) Independent/don","(VOL.) Other party")] <- 2
#dta93$PID[dta93$QD8A=="Republican"] <- 3

dta93$BETPER <- NA
dta93$BETPER[dta93$Q9A=="Better off"] <- 3
dta93$BETPER[dta93$Q9A=="It won"] <- 2
dta93$BETPER[dta93$Q9A=="(DO NOT READ) Don"] <- 2
dta93$BETPER[dta93$Q9A=="Worse off"] <- 1

dta93$BETCOU <- NA
dta93$BETCOU[dta93$Q9B=="Better off"] <- 3
dta93$BETCOU[dta93$Q9B=="It won"] <- 2
dta93$BETCOU[dta93$Q9B=="(DO NOT READ) Don"] <- 2
dta93$BETCOU[dta93$Q9B=="Worse off"] <- 1

#dta93$SUPPORT <- NA
#dta93$SUPPORT[dta93$Q1=="Strongly support"] <- 4
#dta93$SUPPORT[dta93$Q1=="Somewhat support"] <- 3
#dta93$SUPPORT[dta93$Q1=="Somewhat oppose"] <- 2
#dta93$SUPPORT[dta93$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta93$BLACK <- (dta93$QD13=="Black or African-American")*1
dta93$ASIAN <- (dta93$QD13=="Asian")*1
dta93$OTHER <- (dta93$QD13=="Other or mixed race (SPECIFY)")*1

dta93$AGE <- dta93$QD5
dta93$AGE[dta93$AGE==99] <- NA
dta93$MEDICARE <- (dta93$AGE > 64)*1

#dta79$PREEXIST <- (dta79$QD8A=="Yes")*1
dta93$COVERED <- (dta93$QD4=="Covered by health insurance")*1
#dta93$HEALTHNOW <- 1*(dta93$Q1=="It is more important than ever to take on health care reform now")

dta93$IDEO <- NA
dta93$IDEO[dta93$QD9=="Liberal"] <- 3
dta93$IDEO[dta93$QD9=="Moderate"] <- 2
dta93$IDEO[dta93$QD9=="Conservative"] <- 1

dta93$FAVOR <- NA
dta93$FAVOR[dta93$Q7=="Very favorable"] <- 4
dta93$FAVOR[dta93$Q7=="Somewhat favorable"] <- 3
dta93$FAVOR[dta93$Q7=="Somewhat unfavorable"] <- 2
dta93$FAVOR[dta93$Q7=="Very unfavorable"] <- 1

dta93$SELFEMPLOY <- 0
dta93$SELFEMPLOY[dta93$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta93$RETIRED <- 0
dta93$RETIRED[dta93$QD3=="Retired"] <- 1

dta93$MEDICARESR <- 0
dta93$MEDICARESR <- 1*(dta93$QD4A=="Medicare")
dta93$MEDICARESR[dta93$QD4A %in% c(NA)] <- 0

dta93$MEDICAID <- 0
dta93$MEDICAID <- 1*(dta93$QD4A=="Medicaid/Medi-CAL")
dta93$MEDICAID[dta93$QD4A %in% c(NA)] <- 0

#dta93$HEALTH <- NA
#dta93$HEALTH[dta93$QD2=="Excellent"] <- 5
#dta93$HEALTH[dta93$QD2=="Very good"] <- 4
#dta93$HEALTH[dta93$QD2=="Good"] <- 3
#dta93$HEALTH[dta93$QD2=="Only fair"] <- 2
#dta93$HEALTH[dta93$QD2=="Poor"] <- 1

dta93$HEALTH <- NA

dta93$SAWAD <- NA
dta93$SAWADPOS <- NA
dta93$SAWADNEG <- NA
dta93$SAWADBOTH <- NA

dta93$SSTATE <- dta93$STATE

dta93$MALE <- 1*(dta93$QD1=="Male")

dta93$NUMBER <- 93

dta93$MARKET <- NA

dta93$MONTH <- 22

dta93$SELFINSURE <- 0
dta93$SELFINSURE[dta93$QD4A=="Plan you purchased yourself"]<-1

dta93$EMPLINSURE <- 0
dta93$EMPLINSURE[dta93$QD4A=="Plan through your/your spouse"]<-1

dta93$PREEXIST <- NA

#sort(table(dta93$Q2CD[dta93$FAVOR==1]))/sum(sort(table(dta93$Q2CD[dta93$FAVOR==1])))

#lout93a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta93)
#summary(#lout93a)
##mf93a <- model.frame(#lout93a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf93a2 <- subsetn(dta93,select=nms)

#lout93b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta93)
#summary(#lout93b)
##mf93b <- model.frame(#lout93b)

#lout93d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta93)
#summary(#lout93d)
##fv93d <- model.frame(#lout93d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv93a2 <- subsetn(dta93,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s93 <- subsetn(dta93,select=masterlist, subset=T)


####### October 2010
dta92 <- read.csv.lower("hni092.csv")

dta92$INCOME <- NA
dta92$INCOME[dta92$qd14==1] <- 10
dta92$INCOME[dta92$qd14==2] <- 25
dta92$INCOME[dta92$qd14==3] <- 35
dta92$INCOME[dta92$qd14==4] <- 45
dta92$INCOME[dta92$qd14==5] <- 62.5
dta92$INCOME[dta92$qd14==6] <- 82.5
dta92$INCOME[dta92$qd14==7] <- 92
dta92$INCOME[dta92$qd14==8] <- 200

dta92$HISP2 <- dta92$qd12
dta92$HISP <- (dta92$HISP2==1)*1

dta92$EDUC <- NA
dta92$EDUC[dta92$qd11==1] <- 6
dta92$EDUC[dta92$qd11==2] <- 10
dta92$EDUC[dta92$qd11==3] <- 12
dta92$EDUC[dta92$qd11==4] <- 13
dta92$EDUC[dta92$qd11==5] <- 14
dta92$EDUC[dta92$qd11==6] <- 16
dta92$EDUC[dta92$qd11==7] <- 17
dta92$EDUC[dta92$qd11==8] <- 19

dta92$PID <- NA
dta92$PID[dta92$qd8==2] <- 1
dta92$PID[dta92$qd8>=3 & dta92$qd8<=4] <- 2
dta92$PID[dta92$qd8==1] <- 3

dta92$PID5 <- NA
dta92$PID5[dta92$PID==1] <- 1
dta92$PID5[dta92$qd8a==2] <- 2
dta92$PID5[dta92$qd8a %in% c(3, 4, 9)] <- 3
dta92$PID5[dta92$qd8a==1] <- 4
dta92$PID5[dta92$PID==3] <- 5

dta92$REGISTERED <- NA
dta92$REGISTERED[dta92$QD10=="Yes"] <- 1
dta92$REGISTERED[dta92$QD10=="No"] <- 2

dta92$BETPER <- NA
dta92$BETPER[dta92$q8a==1] <- 3
dta92$BETPER[dta92$q8a==3] <- 2
dta92$BETPER[dta92$q8a==9] <- 2
dta92$BETPER[dta92$q8a==2] <- 1

dta92$BETCOU <- NA
dta92$BETCOU[dta92$q8b==1] <- 3
dta92$BETCOU[dta92$q8b==3] <- 2
dta92$BETCOU[dta92$q8b==9] <- 2
dta92$BETCOU[dta92$q8b==2] <- 1


dta92$BETCOU <- NA

# NOTE: var replaced with FAVOR var.
dta92$SUPPORT <- NA
#dta92$SUPPORT[dta92$Q1=="Strongly support"] <- 4
#dta92$SUPPORT[dta92$Q1=="Somewhat support"] <- 3
#dta92$SUPPORT[dta92$Q1=="Somewhat oppose"] <- 2
#dta92$SUPPORT[dta92$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta92$BLACK <- (dta92$qd13==2)*1
dta92$ASIAN <- (dta92$qd13==3)*1
dta92$OTHER <- (dta92$qd13==4)*1

dta92$AGE <- dta92$qd5
dta92$AGE[dta92$AGE==99] <- NA
dta92$MEDICARE <- (dta92$AGE > 64)*1

dta92$COVERED <- (dta92$qd4==1)*1

dta92$IDEO <- NA
dta92$IDEO[dta92$qd9==1] <- 3
dta92$IDEO[dta92$qd9==2] <- 2
dta92$IDEO[dta92$qd9==3] <- 1

dta92$FAVOR <- NA
dta92$FAVOR[dta92$q4==1] <- 4
dta92$FAVOR[dta92$q4==2] <- 3
dta92$FAVOR[dta92$q4==3] <- 2
dta92$FAVOR[dta92$q4==4] <- 1

# Question Still Not Asked
dta92$SELFEMPLOY <- NA
#dta92$SELFEMPLOY[dta92$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta92$RETIRED <- 0
dta92$RETIRED[dta92$qd3==4] <- 1

dta92$MEDICARESR <- 0
dta92$MEDICARESR <- 1*(dta92$qd4a==3)
dta92$MEDICARESR[dta92$COVERED==0] <- 0

dta92$MEDICAID <- 0
dta92$MEDICAID <- 1*(dta92$qd4a==4)
dta92$MEDICAID[dta92$COVERED==0] <- 0

dta92$HEALTH <- NA
dta92$HEALTH[dta92$qd2==1] <- 5
dta92$HEALTH[dta92$qd2==2] <- 4
dta92$HEALTH[dta92$qd2==3] <- 3
dta92$HEALTH[dta92$qd2==4] <- 2
dta92$HEALTH[dta92$qd2==5] <- 1

dta92$SAWAD <- NA
dta92$SAWADPOS <- NA
dta92$SAWADNEG <- NA
dta92$SAWADBOTH <- NA

dta92$SSTATE <- dta92$state
dta92$STATE <- dta92$state

dta92$MALE <- 1*(dta92$sex==1)

dta92$NUMBER <- 92

dta92$MONTH <- 21

dta92$MARKET <- NA

dta92$SELFINSURE <- 0
dta92$SELFINSURE[dta92$qd4a==2]<-1
dta92$SELFINSURE[dta92$COVERED==0] <- 0

dta92$EMPLINSURE <- 0
dta92$EMPLINSURE[dta92$qd4a==1]<-1
dta92$MEDICARESR[dta92$COVERED==0] <- 0

dta92$PREEXIST <- NA

#sort(table(dta92$Q2CD[dta92$FAVOR==1]))/sum(sort(table(dta92$Q2CD[dta92$FAVOR==1])))

#lout92a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta92)
#summary(#lout92a)
##mf92a <- model.frame(#lout92a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf92a2 <- subsetn(dta92,select=nms)

#lout92b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta92)
#summary(#lout92b)
##mf92b <- model.frame(#lout92b)

#lout92d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta92)
#summary(#lout92d)
##fv92d <- model.frame(#lout92d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv92a2 <- subsetn(dta92,select=fvnms)

dta92$PSRAID <- dta92$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s92 <- subsetn(dta92,select=masterlist, subset=T)


####### september 2010
dta91 <- read.csv.lower("hni091.csv")

dta91$INCOME <- NA
dta91$INCOME[dta91$qd14==1] <- 10
dta91$INCOME[dta91$qd14==2] <- 25
dta91$INCOME[dta91$qd14==3] <- 35
dta91$INCOME[dta91$qd14==4] <- 45
dta91$INCOME[dta91$qd14==5] <- 62.5
dta91$INCOME[dta91$qd14==6] <- 82.5
dta91$INCOME[dta91$qd14==7] <- 91
dta91$INCOME[dta91$qd14==8] <- 200

dta91$HISP2 <- dta91$qd12
dta91$HISP <- (dta91$HISP2==1)*1

dta91$EDUC <- NA
dta91$EDUC[dta91$qd11==1] <- 6
dta91$EDUC[dta91$qd11==2] <- 10
dta91$EDUC[dta91$qd11==3] <- 12
dta91$EDUC[dta91$qd11==4] <- 13
dta91$EDUC[dta91$qd11==5] <- 14
dta91$EDUC[dta91$qd11==6] <- 16
dta91$EDUC[dta91$qd11==7] <- 17
dta91$EDUC[dta91$qd11==8] <- 19

dta91$PID <- NA
dta91$PID[dta91$qd8==2] <- 1
dta91$PID[dta91$qd8>=3 & dta91$qd8<=4] <- 2
dta91$PID[dta91$qd8==1] <- 3

dta91$PID5 <- NA
dta91$PID5[dta91$PID==1] <- 1
dta91$PID5[dta91$qd8a==2] <- 2
dta91$PID5[dta91$qd8a %in% c(3, 4, 9)] <- 3
dta91$PID5[dta91$qd8a==1] <- 4
dta91$PID5[dta91$PID==3] <- 5

dta91$REGISTERED <- NA
dta91$REGISTERED[dta91$QD10=="Yes"] <- 1
dta91$REGISTERED[dta91$QD10=="No"] <- 2

dta91$BETPER <- NA
dta91$BETPER[dta91$q7a==1] <- 3
dta91$BETPER[dta91$q7a==3] <- 2
dta91$BETPER[dta91$q7a==9] <- 2
dta91$BETPER[dta91$q7a==2] <- 1

dta91$BETCOU <- NA
dta91$BETCOU[dta91$q7b==1] <- 3
dta91$BETCOU[dta91$q7b==3] <- 2
dta91$BETCOU[dta91$q7b==9] <- 2
dta91$BETCOU[dta91$q7b==2] <- 1

# NOTE: var replaced with FAVOR var.
dta91$SUPPORT <- NA
#dta91$SUPPORT[dta91$Q1=="Strongly support"] <- 4
#dta91$SUPPORT[dta91$Q1=="Somewhat support"] <- 3
#dta91$SUPPORT[dta91$Q1=="Somewhat oppose"] <- 2
#dta91$SUPPORT[dta91$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta91$BLACK <- (dta91$qd13==2)*1
dta91$ASIAN <- (dta91$qd13==3)*1
dta91$OTHER <- (dta91$qd13==4)*1

dta91$AGE <- dta91$qd5
dta91$AGE[dta91$AGE==99] <- NA
dta91$MEDICARE <- (dta91$AGE > 64)*1

dta91$COVERED <- (dta91$qd4==1)*1

dta91$IDEO <- NA
dta91$IDEO[dta91$qd9==1] <- 3
dta91$IDEO[dta91$qd9==2] <- 2
dta91$IDEO[dta91$qd9==3] <- 1

dta91$FAVOR <- NA
dta91$FAVOR[dta91$q4==1] <- 4
dta91$FAVOR[dta91$q4==2] <- 3
dta91$FAVOR[dta91$q4==3] <- 2
dta91$FAVOR[dta91$q4==4] <- 1

# Question Still Not Asked
dta91$SELFEMPLOY <- NA
#dta91$SELFEMPLOY[dta91$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta91$RETIRED <- 0
dta91$RETIRED[dta91$qd3==4] <- 1

dta91$MEDICARESR <- 0
dta91$MEDICARESR <- 1*(dta91$qd4a==3)
dta91$MEDICARESR[dta91$COVERED==0] <- 0

dta91$MEDICAID <- 0
dta91$MEDICAID <- 1*(dta91$qd4a==4)
dta91$MEDICAID[dta91$COVERED==0] <- 0

dta91$HEALTH <- NA
dta91$HEALTH[dta91$qd2==1] <- 5
dta91$HEALTH[dta91$qd2==2] <- 4
dta91$HEALTH[dta91$qd2==3] <- 3
dta91$HEALTH[dta91$qd2==4] <- 2
dta91$HEALTH[dta91$qd2==5] <- 1

dta91$SAWAD <- NA
dta91$SAWADPOS <- NA
dta91$SAWADNEG <- NA
dta91$SAWADBOTH <- NA

dta91$SSTATE <- dta91$state
dta91$STATE <- dta91$state

dta91$MALE <- 1*(dta91$qd1==1)

dta91$NUMBER <- 91

dta91$MONTH <- 20

dta91$MARKET <- NA

dta91$SELFINSURE <- 0
dta91$SELFINSURE[dta91$qd4a==2]<-1
dta91$SELFINSURE[dta91$COVERED==0] <- 0

dta91$EMPLINSURE <- 0
dta91$EMPLINSURE[dta91$qd4a==1]<-1
dta91$EMPLINSURE[dta91$COVERED==0] <- 0

dta91$PREEXIST <- NA

#sort(table(dta91$Q2CD[dta91$FAVOR==1]))/sum(sort(table(dta91$Q2CD[dta91$FAVOR==1])))

#lout91a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta91)
#summary(#lout91a)
##mf91a <- model.frame(#lout91a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf91a2 <- subsetn(dta91,select=nms)

#lout91b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta91)
#summary(#lout91b)
##mf91b <- model.frame(#lout91b)

#lout91d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta91)
#summary(#lout91d)
##fv91d <- model.frame(#lout91d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv91a2 <- subsetn(dta91,select=fvnms)

dta91$PSRAID <- dta91$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s91 <- subsetn(dta91,select=masterlist, subset=T)

####### august 2010
dta90 <- read.csv.lower("hni090.csv")

dta90$INCOME <- NA
dta90$INCOME[dta90$qd14==1] <- 10
dta90$INCOME[dta90$qd14==2] <- 25
dta90$INCOME[dta90$qd14==3] <- 35
dta90$INCOME[dta90$qd14==4] <- 45
dta90$INCOME[dta90$qd14==5] <- 62.5
dta90$INCOME[dta90$qd14==6] <- 82.5
dta90$INCOME[dta90$qd14==7] <- 90
dta90$INCOME[dta90$qd14==8] <- 200

dta90$HISP2 <- dta90$qd12
dta90$HISP <- (dta90$HISP2==1)*1

dta90$EDUC <- NA
dta90$EDUC[dta90$qd11==1] <- 6
dta90$EDUC[dta90$qd11==2] <- 10
dta90$EDUC[dta90$qd11==3] <- 12
dta90$EDUC[dta90$qd11==4] <- 13
dta90$EDUC[dta90$qd11==5] <- 14
dta90$EDUC[dta90$qd11==6] <- 16
dta90$EDUC[dta90$qd11==7] <- 17
dta90$EDUC[dta90$qd11==8] <- 19

dta90$PID <- NA
dta90$PID[dta90$qd8==2] <- 1
dta90$PID[dta90$qd8>=3 & dta90$qd8<=4] <- 2
dta90$PID[dta90$qd8==1] <- 3

dta90$PID5 <- NA
dta90$PID5[dta90$PID==1] <- 1
dta90$PID5[dta90$qd8a==2] <- 2
dta90$PID5[dta90$qd8a %in% c(3, 4, 9)] <- 3
dta90$PID5[dta90$qd8a==1] <- 4
dta90$PID5[dta90$PID==3] <- 5

dta90$REGISTERED <- NA
dta90$REGISTERED[dta90$qd10=="Yes"] <- 1
dta90$REGISTERED[dta90$QD10=="No"] <- 2


dta90$BETPER <- NA
dta90$BETPER[dta90$q6a==1] <- 3
dta90$BETPER[dta90$q6a==3] <- 2
dta90$BETPER[dta90$q6a==9] <- 2
dta90$BETPER[dta90$q6a==2] <- 1

dta90$BETCOU <- NA
dta90$BETCOU[dta90$q6b==1] <- 3
dta90$BETCOU[dta90$q6b==3] <- 2
dta90$BETCOU[dta90$q6b==9] <- 2
dta90$BETCOU[dta90$q6b==2] <- 1

# NOTE: var replaced with FAVOR var.
dta90$SUPPORT <- NA
#dta90$SUPPORT[dta90$Q1=="Strongly support"] <- 4
#dta90$SUPPORT[dta90$Q1=="Somewhat support"] <- 3
#dta90$SUPPORT[dta90$Q1=="Somewhat oppose"] <- 2
#dta90$SUPPORT[dta90$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta90$BLACK <- (dta90$qd13==2)*1
dta90$ASIAN <- (dta90$qd13==3)*1
dta90$OTHER <- (dta90$qd13==4)*1

dta90$AGE <- dta90$qd5
dta90$AGE[dta90$AGE==99] <- NA
dta90$MEDICARE <- (dta90$AGE > 64)*1

dta90$COVERED <- (dta90$qd4==1)*1

dta90$IDEO <- NA
dta90$IDEO[dta90$qd9==1] <- 3
dta90$IDEO[dta90$qd9==2] <- 2
dta90$IDEO[dta90$qd9==3] <- 1

dta90$FAVOR <- NA
dta90$FAVOR[dta90$q4==1] <- 4
dta90$FAVOR[dta90$q4==2] <- 3
dta90$FAVOR[dta90$q4==3] <- 2
dta90$FAVOR[dta90$q4==4] <- 1

# Question Still Not Asked
dta90$SELFEMPLOY <- NA
#dta90$SELFEMPLOY[dta90$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta90$RETIRED <- 0
dta90$RETIRED[dta90$qd3==4] <- 1

dta90$MEDICARESR <- 0
dta90$MEDICARESR <- 1*(dta90$qd4a==3)
dta90$MEDICARESR[dta90$COVERED==0] <- 0

dta90$MEDICAID <- 0
dta90$MEDICAID <- 1*(dta90$qd4a==4)
dta90$MEDICAID[dta90$COVERED==0] <- 0

dta90$HEALTH <- NA
dta90$HEALTH[dta90$qd2==1] <- 5
dta90$HEALTH[dta90$qd2==2] <- 4
dta90$HEALTH[dta90$qd2==3] <- 3
dta90$HEALTH[dta90$qd2==4] <- 2
dta90$HEALTH[dta90$qd2==5] <- 1

dta90$SAWAD <- NA
dta90$SAWADPOS <- NA
dta90$SAWADNEG <- NA
dta90$SAWADBOTH <- NA

dta90$SSTATE <- dta90$state
dta90$STATE <- dta90$state

dta90$MALE <- 1*(dta90$qd1==1)

dta90$NUMBER <- 90

dta90$MONTH <- 19

dta90$MARKET <- NA

dta90$SELFINSURE <- 0
dta90$SELFINSURE[dta90$qd4a==2]<-1
dta90$SELFINSURE[dta90$COVERED==0] <- 0

dta90$EMPLINSURE <- 0
dta90$EMPLINSURE[dta90$qd4a==1]<-1
dta90$EMPLINSURE[dta90$COVERED==0] <- 0

dta90$PREEXIST <- NA

#sort(table(dta90$Q2CD[dta90$FAVOR==1]))/sum(sort(table(dta90$Q2CD[dta90$FAVOR==1])))

#lout90a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta90)
#summary(#lout90a)
##mf90a <- model.frame(#lout90a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf90a2 <- subsetn(dta90,select=nms)

#lout90b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta90)
#summary(#lout90b)
##mf90b <- model.frame(#lout90b)

#lout90d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta90)
#summary(#lout90d)
##fv90d <- model.frame(#lout90d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv90a2 <- subsetn(dta90,select=fvnms)

dta90$PSRAID <- dta90$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s90 <- subsetn(dta90,select=masterlist, subset=T)


######## july 2010
dta89 <- read.por.upper("hni089.por",to.data.frame=T)
#openend <- subsetn(dta89,select=c("Q1","Q2VB"))
#write.table(openend,file="openended.csv",sep=",")

#dta89$QD11 <- dta89$EDUC
#dta89$EDUC <- NULL

#dta89$QD12 <- dta89$HISP
#dta89$HISP <- NULL

dta89$INCOME <- NA
dta89$INCOME[dta89$QD14=="Less than $20,000"] <- 10
dta89$INCOME[dta89$QD14=="$20,000 to less than $30,000"] <- 25
dta89$INCOME[dta89$QD14=="$30,000 to less than $40,000"] <- 35
dta89$INCOME[dta89$QD14=="$40,000 to less than $50,000"] <- 45
dta89$INCOME[dta89$QD14=="$50,000 to less than $75,000"] <- 62.5
dta89$INCOME[dta89$QD14=="$75,000 to less than $90,000"] <- 82.5
dta89$INCOME[dta89$QD14=="$90,000 to less than $100,000"] <- 95
dta89$INCOME[dta89$QD14=="$100,000 or more"] <- 200

dta89$HISP <- (dta89$QD12=="Yes")*1

dta89$EDUC <- NA
dta89$EDUC[dta89$QD11=="None, or grade 1-8"] <- 6
dta89$EDUC[dta89$QD11=="High school incomplete (grades 9-11)"] <- 10
dta89$EDUC[dta89$QD11=="High school graduate (grade 12 or GED certificate)"] <- 12
dta89$EDUC[dta89$QD11=="Technical, trade or vocational school AFTER high school"] <- 13
dta89$EDUC[dta89$QD11=="Some college, no four-year degree (includes associate degree"] <- 14
dta89$EDUC[dta89$QD11=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta89$EDUC[dta89$QD11=="Post-graduate or professional schooling after college"] <- 19

dta89$PID <- NA
dta89$PID[dta89$QD8=="Democrat"] <- 1
dta89$PID[dta89$QD8 %in% c("Independent","Or what (incl. other/none)")] <- 2
dta89$PID[dta89$QD8=="Republican"] <- 3

dta89$REGISTERED <- NA
dta89$REGISTERED[dta89$QD10=="Yes"] <- 1
dta89$REGISTERED[dta89$QD10=="No"] <- 2


dta89$BETPER <- NA
dta89$BETPER[dta89$Q3A=="Better off"] <- 3
dta89$BETPER[dta89$Q3A=="It won"] <- 2
dta89$BETPER[dta89$Q3A=="(DO NOT READ) Don"] <- 2
dta89$BETPER[dta89$Q3A=="Worse off"] <- 1

dta89$BETCOU <- NA
dta89$BETCOU[dta89$Q3B=="Better off"] <- 3
dta89$BETCOU[dta89$Q3B=="It won"] <- 2
dta89$BETCOU[dta89$Q3B=="(DO NOT READ) Don"] <- 2
dta89$BETCOU[dta89$Q3B=="Worse off"] <- 1

#dta89$SUPPORT <- NA
#dta89$SUPPORT[dta89$Q1=="Strongly support"] <- 4
#dta89$SUPPORT[dta89$Q1=="Somewhat support"] <- 3
#dta89$SUPPORT[dta89$Q1=="Somewhat oppose"] <- 2
#dta89$SUPPORT[dta89$Q1=="Strongly oppose"] <- 1


#dta79$QD17
dta89$BLACK <- (dta89$QD13=="Black or African-American")*1
dta89$ASIAN <- (dta89$QD13=="Asian")*1
dta89$OTHER <- (dta89$QD13=="Other or mixed race (SPECIFY)")*1

dta89$AGE <- dta89$QD5
dta89$AGE[dta89$AGE==99] <- NA
dta89$MEDICARE <- (dta89$AGE > 64)*1

#dta79$PREEXIST <- (dta79$QD8A=="Yes")*1
dta89$COVERED <- (dta89$QD4=="Covered by health insurance")*1
#dta89$HEALTHNOW <- 1*(dta89$Q1=="It is more important than ever to take on health care reform now")

dta89$IDEO <- NA
dta89$IDEO[dta89$QD9=="Liberal"] <- 3
dta89$IDEO[dta89$QD9=="Moderate"] <- 2
dta89$IDEO[dta89$QD9=="Conservative"] <- 1

dta89$FAVOR <- NA
dta89$FAVOR[dta89$Q1=="Very favorable"] <- 4
dta89$FAVOR[dta89$Q1=="Somewhat favorable"] <- 3
dta89$FAVOR[dta89$Q1=="Somewhat unfavorable"] <- 2
dta89$FAVOR[dta89$Q1=="Very unfavorable"] <- 1

dta89$SELFEMPLOY <- 0
dta89$SELFEMPLOY[dta89$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta89$RETIRED <- 0
dta89$RETIRED[dta89$QD3=="Retired"] <- 1

dta89$MEDICARESR <- 0
dta89$MEDICARESR <- 1*(dta89$QD4A=="Medicare")
dta89$MEDICARESR[dta89$QD4A %in% c(NA)] <- 0

dta89$MEDICAID <- 0
dta89$MEDICAID <- 1*(dta89$QD4A=="Medicaid/Medi-CAL")
dta89$MEDICAID[dta89$QD4A %in% c(NA)] <- 0

dta89$HEALTH <- NA
dta89$HEALTH[dta89$QD2=="Excellent"] <- 5
dta89$HEALTH[dta89$QD2=="Very good"] <- 4
dta89$HEALTH[dta89$QD2=="Good"] <- 3
dta89$HEALTH[dta89$QD2=="Only fair"] <- 2
dta89$HEALTH[dta89$QD2=="Poor"] <- 1

dta89$SAWAD <- NA
dta89$SAWADPOS <- NA
dta89$SAWADNEG <- NA
dta89$SAWADBOTH <- NA

dta89$MALE <- 1*(dta89$QD1=="Male")

dta89$NUMBER <- 89

dta89$MARKET <- NA

dta89$MONTH <- 18

dta89$SELFINSURE <- 0
dta89$SELFINSURE[dta89$QD4A=="Plan you purchased yourself"]<-1

dta89$EMPLINSURE <- 0
dta89$EMPLINSURE[dta89$QD4A=="Plan through your/your spouse"]<-1

dta89$PREEXIST <- NA

#sort(table(dta89$Q2CD[dta89$FAVOR==1]))/sum(sort(table(dta89$Q2CD[dta89$FAVOR==1])))

#lout89a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta89)
#summary(#lout89a)
##mf89a <- model.frame(#lout89a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf89a2 <- subsetn(dta89,select=nms)

#lout89b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta89)
#summary(#lout89b)
##mf89b <- model.frame(#lout89b)

#lout89d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta89)
#summary(#lout89d)
##fv89d <- model.frame(#lout89d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv89a2 <- subsetn(dta89,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s89 <- subsetn(dta89,select=masterlist, subset=T)


#### june 2010
dta88 <- read.por.upper("hni088.por",to.data.frame=T)

dta88$INCOME <- NA
dta88$INCOME[dta88$QD14=="Less than $20,000"] <- 10
dta88$INCOME[dta88$QD14=="$20,000 to less than $30,000"] <- 25
dta88$INCOME[dta88$QD14=="$30,000 to less than $40,000"] <- 35
dta88$INCOME[dta88$QD14=="$40,000 to less than $50,000"] <- 45
dta88$INCOME[dta88$QD14=="$50,000 to less than $75,000"] <- 62.5
dta88$INCOME[dta88$QD14=="$75,000 to less than $90,000"] <- 82.5
dta88$INCOME[dta88$QD14=="$90,000 to less than $100,000"] <- 95
dta88$INCOME[dta88$QD14=="$100,000 or more"] <- 200

dta88$HISP <- (dta88$QD12=="Yes")*1

dta88$EDUC <- NA
dta88$EDUC[dta88$QD11=="None, or grade 1-8"] <- 6
dta88$EDUC[dta88$QD11=="High school incomplete (grades 9-11)"] <- 10
dta88$EDUC[dta88$QD11=="High school graduate (grade 12 or GED certificate)"] <- 12
dta88$EDUC[dta88$QD11=="Technical, trade or vocational school AFTER high school"] <- 13
dta88$EDUC[dta88$QD11=="Some college, no four-year degree (includes associate degree"] <- 14
dta88$EDUC[dta88$QD11=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta88$EDUC[dta88$QD11=="Post-graduate or professional schooling after college"] <- 19

dta88$PID <- NA
dta88$PID[dta88$QD8=="Democrat"] <- 1
dta88$PID[dta88$QD8 %in% c("Independent","Or what (incl. other/none)")] <- 2
dta88$PID[dta88$QD8=="Republican"] <- 3

dta88$REGISTERED <- NA
dta88$REGISTERED[dta88$QD10=="Yes"] <- 1
dta88$REGISTERED[dta88$QD10=="No"] <- 2


dta88$BETPER <- NA
dta88$BETPER[dta88$Q6A=="Better off"] <- 3
dta88$BETPER[dta88$Q6A=="It won't make much difference"] <- 2
dta88$BETPER[dta88$Q6A=="(DO NOT READ) Don't know/Refused"] <- 2
dta88$BETPER[dta88$Q6A=="Worse off"] <- 1

dta88$BETCOU <- NA
dta88$BETCOU[dta88$Q6B=="Better off"] <- 3
dta88$BETCOU[dta88$Q6B=="It won't make much difference"] <- 2
dta88$BETCOU[dta88$Q6B=="(DO NOT READ) Don't know/Refused"] <- 2
dta88$BETCOU[dta88$Q6B=="Worse off"] <- 1

#dta88$SUPPORT <- NA
#dta88$SUPPORT[dta88$Q1=="Strongly support"] <- 4
#dta88$SUPPORT[dta88$Q1=="Somewhat support"] <- 3
#dta88$SUPPORT[dta88$Q1=="Somewhat oppose"] <- 2
#dta88$SUPPORT[dta88$Q1=="Strongly oppose"] <- 1


#dta79$QD17
dta88$BLACK <- (dta88$QD13=="Black or African-American")*1
dta88$ASIAN <- (dta88$QD13=="Asian")*1
dta88$OTHER <- (dta88$QD13=="Other or mixed race (SPECIFY)")*1

dta88$AGE <- dta88$QD5
dta88$AGE[dta88$AGE==99] <- NA
dta88$MEDICARE <- (dta88$AGE > 64)*1

#dta79$PREEXIST <- (dta79$QD8A=="Yes")*1
dta88$COVERED <- (dta88$QD2=="Covered by health insurance")*1
#dta88$HEALTHNOW <- 1*(dta88$Q1=="It is more important than ever to take on health care reform now")

dta88$IDEO <- NA
dta88$IDEO[dta88$QD9=="Liberal"] <- 3
dta88$IDEO[dta88$QD9=="Moderate"] <- 2
dta88$IDEO[dta88$QD9=="Conservative"] <- 1

dta88$FAVOR <- NA
dta88$FAVOR[dta88$Q5=="Very favorable"] <- 4
dta88$FAVOR[dta88$Q5=="Somewhat favorable"] <- 3
dta88$FAVOR[dta88$Q5=="Somewhat unfavorable"] <- 2
dta88$FAVOR[dta88$Q5=="Very unfavorable"] <- 1

dta88$SELFEMPLOY <- 0
dta88$SELFEMPLOY[dta88$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta88$RETIRED <- 0
dta88$RETIRED[dta88$QD3=="Retired"] <- 1

dta88$MEDICARESR <- 0
dta88$MEDICARESR <- 1*(dta88$QD2A=="Medicare")
dta88$MEDICARESR[dta88$QD2A %in% c(NA)] <- 0

dta88$MEDICAID <- 0
dta88$MEDICAID <- 1*(dta88$QD2A=="Medicaid/Medi-CAL")
dta88$MEDICAID[dta88$QD2A %in% c(NA)] <- 0

dta88$HEALTH <- NA
dta88$HEALTH[dta88$QD4=="Excellent"] <- 5
dta88$HEALTH[dta88$QD4=="Very good"] <- 4
dta88$HEALTH[dta88$QD4=="Good"] <- 3
dta88$HEALTH[dta88$QD4=="Only fair"] <- 2
dta88$HEALTH[dta88$QD4=="Poor"] <- 1

dta88$SAWAD <- NA
dta88$SAWADPOS <- NA
dta88$SAWADNEG <- NA
dta88$SAWADBOTH <- NA

dta88$MALE <- 1*(dta88$QD1=="Male")

dta88$NUMBER <- 88

dta88$MARKET <- NA

dta88$MONTH <- 17

dta88$SELFINSURE <- 0
dta88$SELFINSURE[dta88$QD2A=="Plan you purchased yourself"]<-1

dta88$EMPLINSURE <- 0
dta88$EMPLINSURE[dta88$QD2A=="Plan through your/your spouse's employer"]<-1

dta88$PREEXIST <- NA

#sort(table(dta88$Q2CD[dta88$FAVOR==1]))/sum(sort(table(dta88$Q2CD[dta88$FAVOR==1])))

#lout88a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta88)
#summary(#lout88a)
##mf88a <- model.frame(#lout88a)

#### full data
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf88a2 <- subsetn(dta88,select=nms)

#lout88b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta88)
#summary(#lout88b)
##mf88b <- model.frame(#lout88b)

#lout88d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta88)
#summary(#lout88d)
##fv88d <- model.frame(#lout88d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv88a2 <- subsetn(dta88,select=fvnms)

# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s88 <- subsetn(dta88,select=masterlist, subset=T)

#### may 2010
dta87 <- read.csv.lower("hni087.csv")

dta87$INCOME <- NA
dta87$INCOME[dta87$qd14==1] <- 10
dta87$INCOME[dta87$qd14==2] <- 25
dta87$INCOME[dta87$qd14==3] <- 35
dta87$INCOME[dta87$qd14==4] <- 45
dta87$INCOME[dta87$qd14==5] <- 62.5
dta87$INCOME[dta87$qd14==6] <- 82.5
dta87$INCOME[dta87$qd14==7] <- 87
dta87$INCOME[dta87$qd14==8] <- 200

dta87$HISP2 <- dta87$qd12
dta87$HISP <- (dta87$HISP2==1)*1

dta87$EDUC <- NA
dta87$EDUC[dta87$qd11==1] <- 6
dta87$EDUC[dta87$qd11==2] <- 10
dta87$EDUC[dta87$qd11==3] <- 12
dta87$EDUC[dta87$qd11==4] <- 13
dta87$EDUC[dta87$qd11==5] <- 14
dta87$EDUC[dta87$qd11==6] <- 16
dta87$EDUC[dta87$qd11==7] <- 17
dta87$EDUC[dta87$qd11==8] <- 19

dta87$PID <- NA
dta87$PID[dta87$qd8==2] <- 1
dta87$PID[dta87$qd8>=3 & dta87$qd8<=4] <- 2
dta87$PID[dta87$qd8==1] <- 3

dta87$REGISTERED <- NA
dta87$REGISTERED[dta87$QD10=="Yes"] <- 1
dta87$REGISTERED[dta87$QD10=="No"] <- 2


dta87$BETPER <- NA
dta87$BETPER[dta87$q4a==1] <- 3
dta87$BETPER[dta87$q4a==3] <- 2
dta87$BETPER[dta87$q4a==9] <- 2
dta87$BETPER[dta87$q4a==2] <- 1

dta87$BETCOU <- NA
dta87$BETCOU[dta87$q4b==1] <- 3
dta87$BETCOU[dta87$q4b==3] <- 2
dta87$BETCOU[dta87$q4b==9] <- 2
dta87$BETCOU[dta87$q4b==2] <- 1

# NOTE: var replaced with FAVOR var.
dta87$SUPPORT <- NA
#dta87$SUPPORT[dta87$Q1=="Strongly support"] <- 4
#dta87$SUPPORT[dta87$Q1=="Somewhat support"] <- 3
#dta87$SUPPORT[dta87$Q1=="Somewhat oppose"] <- 2
#dta87$SUPPORT[dta87$Q1=="Strongly oppose"] <- 1

#dta79$QD17
dta87$BLACK <- (dta87$qd13==2)*1
dta87$ASIAN <- (dta87$qd13==3)*1
dta87$OTHER <- (dta87$qd13==4)*1

dta87$AGE <- dta87$qd5
dta87$AGE[dta87$AGE==99] <- NA
dta87$MEDICARE <- (dta87$AGE > 64)*1

dta87$COVERED <- (dta87$qd4==1)*1

dta87$IDEO <- NA
dta87$IDEO[dta87$qd9==1] <- 3
dta87$IDEO[dta87$qd9==2] <- 2
dta87$IDEO[dta87$qd9==3] <- 1

dta87$FAVOR <- NA
dta87$FAVOR[dta87$q1==1] <- 4
dta87$FAVOR[dta87$q1==2] <- 3
dta87$FAVOR[dta87$q1==3] <- 2
dta87$FAVOR[dta87$q1==4] <- 1

# Question Still Not Asked
dta87$SELFEMPLOY <- NA
#dta87$SELFEMPLOY[dta87$QD3=="Self-employed"] <- 1
#dta3$EMPLOYED

dta87$RETIRED <- 0
dta87$RETIRED[dta87$qd3==4] <- 1

dta87$MEDICARESR <- 0
dta87$MEDICARESR <- 1*(dta87$qd4a==3)
dta87$MEDICARESR[dta87$COVERED==0] <- 0

dta87$MEDICAID <- 0
dta87$MEDICAID <- 1*(dta87$qd4a==4)
dta87$MEDICAID[dta87$COVERED==0] <- 0

dta87$HEALTH <- NA
dta87$HEALTH[dta87$qd2==1] <- 5
dta87$HEALTH[dta87$qd2==2] <- 4
dta87$HEALTH[dta87$qd2==3] <- 3
dta87$HEALTH[dta87$qd2==4] <- 2
dta87$HEALTH[dta87$qd2==5] <- 1

dta87$SAWAD <- NA
dta87$SAWADPOS <- NA
dta87$SAWADNEG <- NA
dta87$SAWADBOTH <- NA

dta87$SSTATE <- dta87$state
dta87$STATE <- dta87$state

dta87$MALE <- 1*(dta87$sex==1)

dta87$NUMBER <- 87

dta87$MONTH <- 16

dta87$MARKET <- NA

dta87$SELFINSURE <- 0
dta87$SELFINSURE[dta87$qd4a==2]<-1
dta87$SELFINSURE[dta87$COVERED==0] <- 0

dta87$EMPLINSURE <- 0
dta87$EMPLINSURE[dta87$qd4a==1]<-1
dta87$EMPLINSURE[dta87$COVERED==0] <- 0

dta87$PREEXIST <- NA

#sort(table(dta87$Q2CD[dta87$FAVOR==1]))/sum(sort(table(dta87$Q2CD[dta87$FAVOR==1])))

#lout87a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE +AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta87)
#summary(#lout87a)
##mf87a <- model.frame(#lout87a)

#### full data
nms <- c("NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf87a2 <- subsetn(dta87,select=nms)

#lout87b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE+ AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta87)
#summary(#lout87b)
##mf87b <- model.frame(#lout87b)

#lout87d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta87)
#summary(#lout87d)
##fv87d <- model.frame(#lout87d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv87a2 <- subsetn(dta87,select=fvnms)

dta87$PSRAID <- dta87$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s87 <- subsetn(dta87,select=masterlist, subset=T)



#### april 2010
dta86 <- read.por.upper("hni086.por",to.data.frame=T)

dta86$HEALTH <- NA
dta86$HEALTH[dta86$QD2=="Excellent"] <- 5
dta86$HEALTH[dta86$QD2=="Very good"] <- 4
dta86$HEALTH[dta86$QD2=="Good"] <- 3
dta86$HEALTH[dta86$QD2=="Only fair"] <- 2
dta86$HEALTH[dta86$QD2=="Poor"] <- 1

#dta86$QD11 <- dta86$EDUC
#dta86$EDUC <- NULL

#dta86$QD12 <- dta86$HISP
#dta86$HISP <- NULL

dta86$INCOME <- NA
dta86$INCOME[dta86$QD14=="Less than $20,000"] <- 10
dta86$INCOME[dta86$QD14=="$20,000 to less than $30,000"] <- 25
dta86$INCOME[dta86$QD14=="$30,000 to less than $40,000"] <- 35
dta86$INCOME[dta86$QD14=="$40,000 to less than $50,000"] <- 45
dta86$INCOME[dta86$QD14=="$50,000 to less than $75,000"] <- 62.5
dta86$INCOME[dta86$QD14=="$75,000 to less than $90,000"] <- 82.5
dta86$INCOME[dta86$QD14=="$90,000 to less than $100,000"] <- 95
dta86$INCOME[dta86$QD14=="$100,000 or more"] <- 200

dta86$HISP <- (dta86$QD12=="Yes")*1

dta86$EDUC <- NA
dta86$EDUC[dta86$QD11=="None, or grade 1-8"] <- 6
dta86$EDUC[dta86$QD11=="High school incomplete (grades 9-11)"] <- 10
dta86$EDUC[dta86$QD11=="High school graduate (grade 12 or GED certificate)"] <- 12
dta86$EDUC[dta86$QD11=="Technical, trade or vocational school AFTER high school"] <- 13
dta86$EDUC[dta86$QD11=="Some college, no four-year degree (includes associate degree)"] <- 14
dta86$EDUC[dta86$QD11=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta86$EDUC[dta86$QD11=="Post-graduate or professional schooling after college (e.g., toward a Master's degree or Ph.D; law or medical school)"] <- 19

dta86$PID <- NA
dta86$PID[dta86$QD8=="Democrat"] <- 1
dta86$PID[dta86$QD8 %in% c("Independent","Or what?")] <- 2
dta86$PID[dta86$QD8=="Republican"] <- 3

dta86$REGISTERED <- NA
dta86$REGISTERED[dta86$QD10=="Yes"] <- 1
dta86$REGISTERED[dta86$QD10=="No"] <- 2


dta86$BETPER <- NA
dta86$BETPER[dta86$Q4A=="Better off"] <- 3
dta86$BETPER[dta86$Q4A=="It won"] <- 2
dta86$BETPER[dta86$Q4A=="(DO NOT READ) Don"] <- 2
dta86$BETPER[dta86$Q4A=="Worse off"] <- 1

dta86$BETCOU <- NA
dta86$BETCOU[dta86$Q4B=="Better off"] <- 3
dta86$BETCOU[dta86$Q4B=="It won"] <- 2
dta86$BETCOU[dta86$Q4B=="(DO NOT READ) Don"] <- 2
dta86$BETCOU[dta86$Q4B=="Worse off"] <- 1

dta86$FAVOR <- NA
dta86$FAVOR[dta86$Q2=="Very favorable"] <- 4
dta86$FAVOR[dta86$Q2=="Somewhat favorable"] <- 3
dta86$FAVOR[dta86$Q2=="Somewhat unfavorable"] <- 2
dta86$FAVOR[dta86$Q2=="Very unfavorable"] <- 1

#dta86$SUPPORT <- NA
#dta86$SUPPORT[dta86$Q1=="Strongly support"] <- 4
#dta86$SUPPORT[dta86$Q1=="Somewhat support"] <- 3
#dta86$SUPPORT[dta86$Q1=="Somewhat oppose"] <- 2
#dta86$SUPPORT[dta86$Q1=="Strongly oppose"] <- 1


#dta79$QD17
dta86$BLACK <- (dta86$QD13=="Black or African-American")*1
dta86$ASIAN <- (dta86$QD13=="Asian")*1
dta86$OTHER <- (dta86$QD13=="Other or mixed race (SPECIFY)")*1

#dta86$AGE <- dta86$QD5
dta86$AGE[dta86$AGE==99] <- NA
dta86$MEDICARE <- (dta86$AGE > 64)*1

#dta79$PREEXIST <- (dta79$QD8A=="Yes")*1
dta86$COVERED <- (dta86$QD4=="Covered by health insurance")*1
#dta86$HEALTHNOW <- 1*(dta86$Q1=="It is more important than ever to take on health care reform now")

dta86$MEDICARESR <- 0
dta86$MEDICARESR <- 1*(dta86$QD4A=="Medicare")
dta86$MEDICARESR[dta86$QD4A %in% c(NA)] <- 0

dta86$MEDICAID <- 0
dta86$MEDICAID <- 1*(dta86$QD4A=="Medicaid/Medi-CAL")
dta86$MEDICAID[dta86$QD4A %in% c(NA)] <- 0

dta86$IDEO <- NA
dta86$IDEO[dta86$QD9=="Liberal"] <- 3
dta86$IDEO[dta86$QD9=="Moderate"] <- 2
dta86$IDEO[dta86$QD9=="Conservative"] <- 1

dta86$SAWAD <- NA
dta86$SAWADPOS <- NA
dta86$SAWADNEG <- NA
dta86$SAWADBOTH <- NA

dta86$MALE <- 1*(dta86$QD1=="Male")

dta86$NUMBER <- 86

dta86$MARKET <- NA

dta86$MONTH <- 15

dta86$RETIRED <- (dta86$QD3=="Retired")*1

dta86$SELFINSURE <- 0
dta86$SELFINSURE[dta86$QD4A=="Plan you purchased yourself"]<-1

dta86$EMPLINSURE <- 0
dta86$EMPLINSURE[dta86$QD4A=="Plan through your/your spouse"]<-1

dta86$PREEXIST <- NA

#lout86a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta86)
#summary(#lout86a)
##mf86a <- model.frame(#lout86a)

#lout86b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta86)
#summary(#lout86b)
##mf86b <- model.frame(#lout86b)

nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf86a2 <- subsetn(dta86,select=nms)

#lout86d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta86)
#summary(#lout86d)
##fv86d <- model.frame(#lout86d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv86a2 <- subsetn(dta86,select=fvnms)


# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s86 <- subsetn(dta86,select=masterlist, subset=T)


### MARCH 2010
dta85 <- read.por.upper("hni085.por",to.data.frame=T)
dta85$QD11 <- dta85$EDUC
dta85$EDUC <- NULL

dta85$QD12 <- dta85$HISP
dta85$HISP <- NULL

dta85$HEALTH <- NA
dta85$HEALTH[dta85$QD4=="Excellent"] <- 5
dta85$HEALTH[dta85$QD4=="Very good"] <- 4
dta85$HEALTH[dta85$QD4=="Good"] <- 3
dta85$HEALTH[dta85$QD4=="Only fair"] <- 2
dta85$HEALTH[dta85$QD4=="Poor"] <- 1


dta85$INCOME <- NA
dta85$INCOME[dta85$QD14=="Less than $20,000"] <- 10
dta85$INCOME[dta85$QD14=="$20,000 to less than $30,000"] <- 25
dta85$INCOME[dta85$QD14=="$30,000 to less than $40,000"] <- 35
dta85$INCOME[dta85$QD14=="$40,000 to less than $50,000"] <- 45
dta85$INCOME[dta85$QD14=="$50,000 to less than $75,000"] <- 62.5
dta85$INCOME[dta85$QD14=="$75,000 to less than $90,000"] <- 82.5
dta85$INCOME[dta85$QD14=="$90,000 to less than $100,000"] <- 95
dta85$INCOME[dta85$QD14=="$100,000 or more"] <- 200

dta85$HISP <- (dta85$QD12=="Yes")*1

dta85$EDUC <- NA
dta85$EDUC[dta85$QD11=="None, or grade 1-8"] <- 6
dta85$EDUC[dta85$QD11=="High school incomplete (grades 9-11)"] <- 10
dta85$EDUC[dta85$QD11=="High school graduate (grade 12 or GED certificate)"] <- 12
dta85$EDUC[dta85$QD11=="Technical, trade or vocational school AFTER high school"] <- 13
dta85$EDUC[dta85$QD11=="Some college, no four-year degree (includes associate degree)"] <- 14
dta85$EDUC[dta85$QD11=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta85$EDUC[dta85$QD11=="Post-graduate or professional schooling after college (e.g., toward a Master's degree or Ph.D; law or medical school)"] <- 19

dta85$PID <- NA
dta85$PID[dta85$QD8=="Democrat"] <- 1
dta85$PID[dta85$QD8 %in% c("Independent","Or what?")] <- 2
dta85$PID[dta85$QD8=="Republican"] <- 3

dta85$REGISTERED <- NA
dta85$REGISTERED[dta85$QD10=="Yes"] <- 1
dta85$REGISTERED[dta85$QD10=="No"] <- 2


dta85$BETPER <- NA
dta85$BETPER[dta85$Q2A=="Better off "] <- 3
dta85$BETPER[dta85$Q2A=="(VOL.) It depends"] <- 2
dta85$BETPER[dta85$Q2A=="Wouldn"] <- 2
dta85$BETPER[dta85$Q2A=="Worse off"] <- 1

dta85$BETCOU <- NA
dta85$BETCOU[dta85$Q2B=="Better off "] <- 3
dta85$BETCOU[dta85$Q2B=="(VOL.) It depends"] <- 2
dta85$BETCOU[dta85$Q2B=="Wouldn"] <- 2
dta85$BETCOU[dta85$Q2B=="Worse off"] <- 1

dta85$SUPPORT <- NA
dta85$SUPPORT[dta85$Q1=="Strongly support"] <- 4
dta85$SUPPORT[dta85$Q1=="Somewhat support"] <- 3
dta85$SUPPORT[dta85$Q1=="Somewhat oppose"] <- 2
dta85$SUPPORT[dta85$Q1=="Strongly oppose"] <- 1

dta85$FAVOR <- dta85$SUPPORT

dta85$SAWAD <- NA
dta85$SAWADPOS <- NA
dta85$SAWADNEG <- NA
dta85$SAWADBOTH <- NA

#dta79$QD17
dta85$BLACK <- (dta85$RACE=="Black or African-American")*1
dta85$ASIAN <- (dta85$RACE=="Asian")*1
dta85$OTHER <- (dta85$RACE=="Other or mixed race (SPECIFY)")*1

#dta85$AGE <- dta85$QD5
dta85$AGE[dta85$AGE==99] <- NA
dta85$MEDICARE <- (dta85$AGE > 64)*1

#dta79$PREEXIST <- (dta79$QD8A=="Yes")*1
dta85$COVERED <- (dta85$QD2=="Covered by health insurance")*1
#dta85$HEALTHNOW <- 1*(dta85$Q1=="It is more important than ever to take on health care reform now")

dta85$IDEO <- NA
dta85$IDEO[dta85$QD9=="Liberal"] <- 3
dta85$IDEO[dta85$QD9=="Moderate"] <- 2
dta85$IDEO[dta85$QD9=="Conservative"] <- 1

dta85$MEDICARESR <- 0
dta85$MEDICARESR <- 1*(dta85$QD2A=="Medicare ")
dta85$MEDICARESR[dta85$QD2A %in% c(NA)] <- 0

dta85$MEDICAID <- 0
dta85$MEDICAID <- 1*(dta85$QD2A=="Medicaid/Medi-CAL")
dta85$MEDICAID[dta85$QD2A %in% c(NA)] <- 0

dta85$SSTATE <- dta85$STATE

dta85$MALE <- 1*(dta85$QD1=="Male")

dta85$NUMBER <- 85

dta85$MARKET <- NA

dta85$MONTH <- 14

dta85$RETIRED <- (dta85$QD3=="Retired")*1

dta85$SELFINSURE <- 0
dta85$SELFINSURE[dta85$QD2A=="Plan you purchased yourself"]<-1

dta85$EMPLINSURE <- 0
dta85$EMPLINSURE[dta85$QD2A=="Plan through your employer"]<-1
dta85$EMPLINSURE[dta85$QD2A=="Plan through your spouse"]<-1

dta85$PREEXIST <- NA

#lout85a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta85)
#summary(#lout85a)
##mf85a <- model.frame(#lout85a)

#lout85b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta85)
#summary(#lout85b)
##mf85b <- model.frame(#lout85b)

#lout85d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta85)
#summary(#lout85d)
##fv85d <- model.frame(#lout85d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv85a2 <- subsetn(dta85,select=fvnms)

nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf85a2 <- subsetn(dta85,select=nms)


# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s85 <- subsetn(dta85,select=masterlist, subset=T)

### FEBRUARY 2010
dta84 <- read.por.upper("hni084.por",to.data.frame=T)

dta84$MALE <- 1*(dta84$QD1=="Male")

dta84$HEALTH <- NA
dta84$HEALTH[dta84$QD2=="Excellent"] <- 5
dta84$HEALTH[dta84$QD2=="Very good"] <- 4
dta84$HEALTH[dta84$QD2=="Good"] <- 3
dta84$HEALTH[dta84$QD2=="Only fair"] <- 2
dta84$HEALTH[dta84$QD2=="Poor"] <- 1

dta84$INCOME <- NA
dta84$INCOME[dta84$QD15=="Less than $20,000"] <- 10
dta84$INCOME[dta84$QD15=="$20,000 to less than $30,000"] <- 25
dta84$INCOME[dta84$QD15=="$30,000 to less than $40,000"] <- 35
dta84$INCOME[dta84$QD15=="$40,000 to less than $50,000"] <- 45
dta84$INCOME[dta84$QD15=="$50,000 to less than $75,000"] <- 62.5
dta84$INCOME[dta84$QD15=="$75,000 to less than $90,000"] <- 82.5
dta84$INCOME[dta84$QD15=="$90,000 to less than $100,000"] <- 95
dta84$INCOME[dta84$QD15=="$100,000 or more"] <- 200

dta84$HISP <- (dta84$QD13=="Yes")*1

dta84$EDUC <- NA
dta84$EDUC[dta84$QD12=="None, or grade 1-8"] <- 6
dta84$EDUC[dta84$QD12=="High school incomplete (grades 9-11)"] <- 10
dta84$EDUC[dta84$QD12=="High school graduate (grade 12 or GED certificate)"] <- 12
dta84$EDUC[dta84$QD12=="Technical, trade or vocational school AFTER high school"] <- 13
dta84$EDUC[dta84$QD12=="Some college, no four-year degree (includes associate degree)"] <- 14
dta84$EDUC[dta84$QD12=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta84$EDUC[dta84$QD12=="Post-graduate or professional schooling after college (e.g., toward a Master's degree or Ph.D; law or medical school)"] <- 19

dta84$PID <- NA
dta84$PID[dta84$QD8=="Democrat"] <- 1
dta84$PID[dta84$QD8 %in% c("Independent","Or what?")] <- 2
dta84$PID[dta84$QD8=="Republican"] <- 3

dta84$REGISTERED <- NA
dta84$REGISTERED[dta84$QD10=="Yes"] <- 1
dta84$REGISTERED[dta84$QD10=="No"] <- 2


dta84$BETPER <- NA
dta84$BETPER[dta84$Q2A=="Better off "] <- 3
dta84$BETPER[dta84$Q2A=="(VOL.) It depends"] <- 2
dta84$BETPER[dta84$Q2A=="Wouldn"] <- 2
dta84$BETPER[dta84$Q2A=="Worse off"] <- 1

dta84$BETCOU <- NA
dta84$BETCOU[dta84$Q2B=="Better off "] <- 3
dta84$BETCOU[dta84$Q2B=="(VOL.) It depends"] <- 2
dta84$BETCOU[dta84$Q2B=="Wouldn"] <- 2
dta84$BETCOU[dta84$Q2B=="Worse off"] <- 1

dta84$SUPPORT <- NA
dta84$SUPPORT[dta84$Q1=="Strongly support"] <- 4
dta84$SUPPORT[dta84$Q1=="Somewhat support"] <- 3
dta84$SUPPORT[dta84$Q1=="Somewhat oppose"] <- 2
dta84$SUPPORT[dta84$Q1=="Strongly oppose"] <- 1

dta84$FAVOR <- dta84$SUPPORT


#dta79$QD17
dta84$BLACK <- (dta84$QD14=="Black or African-American")*1
dta84$ASIAN <- (dta84$QD14=="Asian")*1
dta84$OTHER <- (dta84$QD14=="Other or mixed race (SPECIFY)")*1

dta84$AGE <- dta84$QD5
dta84$AGE[dta84$QD5==99] <- NA
dta84$MEDICARE <- (dta84$AGE > 64)*1

#dta79$PREEXIST <- (dta79$QD8A=="Yes")*1
dta84$COVERED <- (dta84$QD4=="Covered by health insurance")*1
#dta84$HEALTHNOW <- 1*(dta84$Q1=="It is more important than ever to take on health care reform now")

dta84$IDEO <- NA
dta84$IDEO[dta84$QD9=="Liberal"] <- 3
dta84$IDEO[dta84$QD9=="Moderate"] <- 2
dta84$IDEO[dta84$QD9=="Conservative"] <- 1

dta84$MEDICARESR <- 0
dta84$MEDICARESR <- 1*(dta84$QD4A=="Medicare")
dta84$MEDICARESR[dta84$QD4A %in% c(NA)] <- 0

dta84$MEDICAID <- 0
dta84$MEDICAID <- 1*(dta84$QD4A=="Medicaid/Medi-CAL")
dta84$MEDICAID[dta84$QD4A %in% c(NA)] <- 0

dta84$SAWAD <- NA
dta84$SAWADPOS <- NA
dta84$SAWADNEG <- NA
dta84$SAWADBOTH <- NA

dta84$NUMBER <- 84

dta84$MARKET <- NA

dta84$MONTH <- 13

dta84$RETIRED <- (dta84$QD3=="Retired")*1

dta84$SELFINSURE <- 0
dta84$SELFINSURE[dta84$QD4A=="Plan you purchased yourself"]<-1

dta84$EMPLINSURE <- 0
dta84$EMPLINSURE[dta84$QD4A=="Plan through your/your spouse"]<-1

dta84$PREEXIST <- NA

#lout84a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta84)
#summary(#lout84a)
##mf84a <- model.frame(#lout84a)

#lout84b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta84)
#summary(#lout84b)
##mf84b <- model.frame(#lout84b)

nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf84a2 <- subsetn(dta84,select=nms)


###lout84c <- glm(HEALTHNOW ~ MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta84)
##summary(#lout84c)
###mf84 <- model.frame(#lout84c)
#cn <- colnames(#mf)

#lout84d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta84)
#summary(#lout84d)
##fv84d <- model.frame(#lout84d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv84a2 <- subsetn(dta84,select=fvnms)


# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s84 <- subsetn(dta84,select=masterlist, subset=T)


### JANUARY 2010
dta83 <- read.por.upper("hni083.por",to.data.frame=T)

dta83$MALE <- 1*(dta83$QD1=="Male")

dta83$HEALTH <- NA
dta83$HEALTH[dta83$QD2=="Excellent"] <- 5
dta83$HEALTH[dta83$QD2=="Very good"] <- 4
dta83$HEALTH[dta83$QD2=="Good"] <- 3
dta83$HEALTH[dta83$QD2=="Only fair"] <- 2
dta83$HEALTH[dta83$QD2=="Poor"] <- 1

dta83$INCOME <- NA
dta83$INCOME[dta83$QD13=="Less than $20,000"] <- 10
dta83$INCOME[dta83$QD13=="$20,000 to less than $30,000"] <- 25
dta83$INCOME[dta83$QD13=="$30,000 to less than $40,000"] <- 35
dta83$INCOME[dta83$QD13=="$40,000 to less than $50,000"] <- 45
dta83$INCOME[dta83$QD13=="$50,000 to less than $75,000"] <- 62.5
dta83$INCOME[dta83$QD13=="$75,000 to less than $90,000"] <- 82.5
dta83$INCOME[dta83$QD13=="$90,000 to less than $100,000"] <- 95
dta83$INCOME[dta83$QD13=="$100,000 or more"] <- 200


dta83$HISP <- (dta83$QD11=="Yes")*1

dta83$EDUC <- NA
dta83$EDUC[dta83$QD9=="None, or grade 1-8"] <- 6
dta83$EDUC[dta83$QD9=="High school incomplete (grades 9-11)"] <- 10
dta83$EDUC[dta83$QD9=="High school graduate (grade 12 or GED certificate)"] <- 12
dta83$EDUC[dta83$QD9=="Technical, trade or vocational school AFTER high school"] <- 13
dta83$EDUC[dta83$QD9=="Some college, no four-year degree (includes associate degree)"] <- 14
dta83$EDUC[dta83$QD9=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta83$EDUC[dta83$QD9=="Post-graduate or professional schooling after college (e.g., toward a Master's degree or Ph.D; law or medical school)"] <- 19

dta83$PID <- NA
dta83$PID[dta83$QD8=="Democrat"] <- 1
dta83$PID[dta83$QD8 %in% c("Independent","Or what?")] <- 2
dta83$PID[dta83$QD8=="Republican"] <- 3

dta83$BETPER <- NA
dta83$BETPER[dta83$Q4A=="Better off "] <- 3
dta83$BETPER[dta83$Q4A=="(VOL.) It depends"] <- 2
dta83$BETPER[dta83$Q4A=="Wouldn"] <- 2
dta83$BETPER[dta83$Q4A=="Worse off"] <- 1

dta83$BETCOU <- NA
dta83$BETCOU[dta83$Q4B=="Better off "] <- 3
dta83$BETCOU[dta83$Q4B=="(VOL.) It depends"] <- 2
dta83$BETCOU[dta83$Q4B=="Wouldn"] <- 2
dta83$BETCOU[dta83$Q4B=="Worse off"] <- 1

dta83$SUPPORT <- NA
dta83$SUPPORT[dta83$Q3=="Strongly support"] <- 4
dta83$SUPPORT[dta83$Q3=="Somewhat support"] <- 3
dta83$SUPPORT[dta83$Q3=="Somewhat oppose"] <- 2
dta83$SUPPORT[dta83$Q3=="Strongly oppose"] <- 1

dta83$FAVOR <- dta83$SUPPORT


#dta79$QD17
dta83$BLACK <- (dta83$QD12=="Black or African-American")*1
dta83$ASIAN <- (dta83$QD12=="Asian")*1
dta83$OTHER <- (dta83$QD12=="Other or mixed race (SPECIFY)")*1

dta83$AGE <- dta83$QD5
dta83$AGE[dta83$QD5==99] <- NA
dta83$MEDICARE <- (dta83$AGE > 64)*1

#dta79$PREEXIST <- (dta79$QD8A=="Yes")*1
dta83$COVERED <- (dta83$QD4=="Covered by health insurance")*1
dta83$HEALTHNOW <- 1*(dta83$Q1=="It is more important than ever to take on health care reform now")

dta83$MEDICARESR <- 0
dta83$MEDICARESR <- 1*(dta83$QD4A=="Medicare")
dta83$MEDICARESR[dta83$QD4A %in% c(NA)] <- 0

dta83$MEDICAID <- 0
dta83$MEDICAID <- 1*(dta83$QD4A=="Medicaid/Medi-CAL")
dta83$MEDICAID[dta83$QD4A %in% c(NA)] <- 0

dta83$SAWAD <- NA
dta83$SAWADPOS <- NA
dta83$SAWADNEG <- NA
dta83$SAWADBOTH <- NA

dta83$NUMBER <- 83

dta83$MARKET <- NA

dta83$MONTH <- 12

dta83$RETIRED <- (dta83$QD3=="Retired")*1

dta83$SELFINSURE <- 0
dta83$SELFINSURE[dta83$QD4A=="Plan you purchased yourself"]<-1

dta83$EMPLINSURE <- 0
dta83$EMPLINSURE[dta83$QD4A=="Plan through your/your spouse"]<-1

dta83$PREEXIST <- NA

#lout83a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta83)
#summary(#lout83a)
##mf83a <- model.frame(#lout83a)


#lout83b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta83)
#summary(#lout83b)
##mf83b <- model.frame(#lout83b)

dta83$IDEO <- NA

nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf83a2 <- subsetn(dta83,select=nms)


#lout83c <- glm(HEALTHNOW ~ MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta83)
#summary(#lout83c)
##mf83 <- model.frame(#lout83c)

#lout83d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta83)
#summary(#lout83d)
##fv83d <- model.frame(#lout83d)
fvnms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#fv83a2 <- subsetn(dta83,select=fvnms)
#cn <- colnames(#mf)


# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s83 <- subsetn(dta83,select=masterlist, subset=T)


### DECEMBER 2009
dta82 <- read.por.upper("hni082.por",to.data.frame=T)

dta82$MALE <- 1*(dta82$QD1=="Male")

dta82$HEALTH <- NA
dta82$HEALTH[dta82$QD2=="Excellent"] <- 5
dta82$HEALTH[dta82$QD2=="Very good"] <- 4
dta82$HEALTH[dta82$QD2=="Good"] <- 3
dta82$HEALTH[dta82$QD2=="Only fair"] <- 2
dta82$HEALTH[dta82$QD2=="Poor"] <- 1


dta82$INCOME <- NA
dta82$INCOME[dta82$QD13=="Less than $20,000"] <- 10
dta82$INCOME[dta82$QD13=="$20,000 to less than $30,000"] <- 25
dta82$INCOME[dta82$QD13=="$30,000 to less than $40,000"] <- 35
dta82$INCOME[dta82$QD13=="$40,000 to less than $50,000"] <- 45
dta82$INCOME[dta82$QD13=="$50,000 to less than $75,000"] <- 62.5
dta82$INCOME[dta82$QD13=="$75,000 to less than $90,000"] <- 82.5
dta82$INCOME[dta82$QD13=="$90,000 to less than $100,000"] <- 95
dta82$INCOME[dta82$QD13=="$100,000 or more"] <- 200


dta82$HISP <- (dta82$QD11=="Yes")*1

dta82$EDUC <- NA
dta82$EDUC[dta82$QD9=="None, or grade 1-8"] <- 6
dta82$EDUC[dta82$QD9=="High school incomplete (grades 9-11)"] <- 10
dta82$EDUC[dta82$QD9=="High school graduate (grade 12 or GED certificate)"] <- 12
dta82$EDUC[dta82$QD9=="Technical, trade or vocational school AFTER high school"] <- 13
dta82$EDUC[dta82$QD9=="Some college, no four-year degree (includes associate degree)"] <- 14
dta82$EDUC[dta82$QD9=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta82$EDUC[dta82$QD9=="Post-graduate or professional schooling after college (e.g., toward a Master's degree or Ph.D; law or medical school)"] <- 19

dta82$PID <- NA
dta82$PID[dta82$QD8=="Democrat"] <- 1
dta82$PID[dta82$QD8 %in% c("Independent","Or what?")] <- 2
dta82$PID[dta82$QD8=="Republican"] <- 3

dta82$BETPER <- NA
dta82$BETPER[dta82$Q3A=="Better off "] <- 3
dta82$BETPER[dta82$Q3A=="(VOL.) It depends"] <- 2
dta82$BETPER[dta82$Q3A=="Wouldn"] <- 2
dta82$BETPER[dta82$Q3A=="Worse off"] <- 1

dta82$BETCOU <- NA
dta82$BETCOU[dta82$Q3B=="Better off "] <- 3
dta82$BETCOU[dta82$Q3B=="(VOL.) It depends"] <- 2
dta82$BETCOU[dta82$Q3B=="Wouldn"] <- 2
dta82$BETCOU[dta82$Q3B=="Worse off"] <- 1

#dta79$QD17
dta82$BLACK <- (dta82$QD12=="Black or African-American")*1
dta82$ASIAN <- (dta82$QD12=="Asian")*1
dta82$OTHER <- (dta82$QD12=="Other or mixed race (SPECIFY)")*1

dta82$MEDICARE <- (dta82$QD5 > 64)*1
#dta79$PREEXIST <- (dta79$QD8A=="Yes")*1
dta82$COVERED <- (dta82$QD4=="Covered by health insurance")*1
dta82$HEALTHNOW <- 1*(dta82$Q1=="It is more important than ever to take on health care reform now")

dta82$AGE <- dta82$QD5
dta82$AGE[dta82$QD5==99] <- NA

dta82$MEDICARESR <- 0
dta82$MEDICARESR <- 1*(dta82$QD4A=="Medicare")
dta82$MEDICARESR[dta82$QD4A %in% c(NA)] <- 0

dta82$MEDICAID <- 0
dta82$MEDICAID <- 1*(dta82$QD4A=="Medicaid/Medi-CAL")
dta82$MEDICAID[dta82$QD4A %in% c(NA)] <- 0

dta82$SAWAD <- 1*(dta82$Q10=="Yes")
dta82$SAWADPOS <- 1*(dta82$Q11=="Have seen ads in favor of passing some sort of health care reform this year")
dta82$SAWADNEG <- 1*(dta82$Q11=="Have seen ads opposed to passing some sort of health care reform this year")
dta82$SAWADBOTH <- 1*(dta82$Q11=="(VOL.) Have seen both ads in favor and opposed")

dta82$NUMBER <- 82

dta82$MARKET <- NA

dta82$MONTH <- 11

dta82$SELFINSURE <- 0
dta82$SELFINSURE[dta82$QD4A=="Plan you purchased yourself"]<-1

dta82$EMPLINSURE <- 0
dta82$EMPLINSURE[dta82$QD4A=="Plan through your/your spouse"]<-1

dta82$PREEXIST <- NA

dta82$RETIRED <- NA

#lout82a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta82)
#summary(#lout82a)
##mf82a <- model.frame(#lout82a)

#lout82b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta82)
#summary(#lout82b)
##mf82b <- model.frame(#lout82b)

dta82$IDEO <- NA
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf82a2 <- subsetn(dta82,select=nms)


#lout82c <- glm(HEALTHNOW ~ MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta82)
#summary(#lout82c)
##mf82 <- model.frame(#lout82c)
#cn <- colnames(#mf)

dta82$MARKET <- NA
dta82$FAVOR <- NA


# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s82 <- subsetn(dta82,select=masterlist, subset=T)

### read NOVEMBER 2009
dta81 <- read.por.upper("hni081.por",to.data.frame=T)

dta81$MALE <- 1*(dta81$QD1=="Male")

dta81$HEALTH <- NA
dta81$HEALTH[dta81$QD2=="Excellent"] <- 5
dta81$HEALTH[dta81$QD2=="Very good"] <- 4
dta81$HEALTH[dta81$QD2=="Good"] <- 3
dta81$HEALTH[dta81$QD2=="Only fair"] <- 2
dta81$HEALTH[dta81$QD2=="Poor"] <- 1

dta81$INCOME <- NA
dta81$INCOME[dta81$QD13=="Less than $20,000"] <- 10
dta81$INCOME[dta81$QD13=="$20,000 to less than $30,000"] <- 25
dta81$INCOME[dta81$QD13=="$30,000 to less than $40,000"] <- 35
dta81$INCOME[dta81$QD13=="$40,000 to less than $50,000"] <- 45
dta81$INCOME[dta81$QD13=="$50,000 to less than $75,000"] <- 62.5
dta81$INCOME[dta81$QD13=="$75,000 to less than $90,000"] <- 82.5
dta81$INCOME[dta81$QD13=="$90,000 to less than $100,000"] <- 95
dta81$INCOME[dta81$QD13=="$100,000 or more"] <- 200

dta81$HISP <- (dta81$QD11=="Yes")*1

dta81$EDUC <- NA
dta81$EDUC[dta81$QD9=="None, or grade 1-8"] <- 6
dta81$EDUC[dta81$QD9=="High school incomplete (grades 9-11)"] <- 10
dta81$EDUC[dta81$QD9=="High school graduate (grade 12 or GED certificate)"] <- 12
dta81$EDUC[dta81$QD9=="Technical, trade or vocational school AFTER high school"] <- 13
dta81$EDUC[dta81$QD9=="Some college, no four-year degree (includes associate degree)"] <- 14
dta81$EDUC[dta81$QD9=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta81$EDUC[dta81$QD9=="Post-graduate or professional schooling after college (e.g., toward a Master's degree or Ph.D; law or medical school)"] <- 19

dta81$PID <- NA
dta81$PID[dta81$QD8=="Democrat"] <- 1
dta81$PID[dta81$QD8 %in% c("Independent","Or what?")] <- 2
dta81$PID[dta81$QD8=="Republican"] <- 3

dta81$BETPER <- NA
dta81$BETPER[dta81$Q6A=="Better off "] <- 3
dta81$BETPER[dta81$Q6A=="(VOL.) It depends"] <- 2
dta81$BETPER[dta81$Q6A=="Wouldn"] <- 2
dta81$BETPER[dta81$Q6A=="Worse off"] <- 1

dta81$BETCOU <- NA
dta81$BETCOU[dta81$Q6B=="Better off "] <- 3
dta81$BETCOU[dta81$Q6B=="(VOL.) It depends"] <- 2
dta81$BETCOU[dta81$Q6B=="Wouldn"] <- 2
dta81$BETCOU[dta81$Q6B=="Worse off"] <- 1

#dta79$QD17
dta81$BLACK <- (dta81$QD12=="Black or African-American")*1
dta81$ASIAN <- (dta81$QD12=="Asian")*1
dta81$OTHER <- (dta81$QD12=="Other or mixed race (SPECIFY)")*1

#dta79$PREEXIST <- (dta79$QD8A=="Yes")*1
dta81$COVERED <- (dta81$QD4=="Covered by health insurance")*1
dta81$HEALTHNOW <- 1*(dta81$Q1=="It is more important than ever to take on health care reform now")

dta81$AGE <- dta81$QD5
dta81$AGE[dta81$QD5==99] <- NA
dta81$MEDICARE <- (dta81$AGE > 64)*1


dta81$MEDICARESR <- 0
dta81$MEDICARESR <- 1*(dta81$QD4A=="Medicare")
dta81$MEDICARESR[dta81$QD4A %in% c(NA)] <- 0

dta81$MEDICAID <- 0
dta81$MEDICAID <- 1*(dta81$QD4A=="Medicaid/Medi-CAL")
dta81$MEDICAID[dta81$QD4A %in% c(NA)] <- 0

dta81$SAWAD <- 1*(dta81$Q14=="Yes")
dta81$SAWADPOS <- 1*(dta81$Q15=="Have seen ads in favor of passing some sort of health care reform this year")
dta81$SAWADNEG <- 1*(dta81$Q15=="Have seen ads opposed to passing some sort of health care reform this year")
dta81$SAWADBOTH <- 1*(dta81$Q15=="(VOL.) Have seen both ads in favor and opposed")

dta81$NUMBER <- 81

dta81$MARKET <- NA

dta81$MONTH <- 10

dta81$SELFINSURE <- 0
dta81$SELFINSURE[dta81$QD4A=="Plan you purchased yourself"]<-1

dta81$EMPLINSURE <- 0
dta81$EMPLINSURE[dta81$QD4A=="Plan through your/your spouse"]<-1

dta81$PREEXIST <- NA

#lout81a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta81)
#summary(#lout81a)
##mf81a <- model.frame(#lout81a)

#lout81b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta81)
#summary(#lout81b)
##mf81b <- model.frame(#lout81b)

dta81$SSTATE <- dta81$STATE

dta81$IDEO <- NA

nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf81a2 <- subsetn(dta81,select=nms)

#lout81c <- glm(HEALTHNOW ~ MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta81)
#summary(#lout81c)
##mf81 <- model.frame(#lout81c)
#cn <- colnames(#mf)


dta81$FAVOR <- NA
dta81$RETIRED <- NA
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s81 <- subsetn(dta81,select=masterlist, subset=T)

##### OCTOBER 2009
#dta80 <- read.fwf("hni080.dat",widths=c(6,1,4,3,2,1,1,1,1,1,1,2,1,1,1,1,1,1,rep(1,31),rep(1,17),2,rep(1,19),4,4,5,8,8,8,8,150,150))
#dta80 <- read.por.upper("hni080.por")
dta80 <- NULL
#colnames(dta80) <- toupper(c("psraid","sample","date","area","state","cregion","density","usr","stz","rep","scregion","sstate","susr","lang","form","qs1","qd1","q1","q2","q3","q4a","q4b","q4c","q4d","q5a","q5b","q5c","q5d","q6a","q6b","q6c","q6d","q7a","q7b","q8","q9","q10","q11","q12a","q12b","q12c","q12d","q12e","q12f","q12g","q13","q14","q15","q16","q17a","q17b","q18","q19","q20","q21","q22a","q22b","q22c","q23","q24","q25","q26","qd8","qd7","qd2","qd2a","qd9","qd10","qd11","qd13","qd14","qd15","qd16","qd17","q11","q11a","q12","qc1","qc2","hh1","money","recage2","phoneuse","recage","receduc","racethn","pua","psa","weight","total","wt_sq","receduc2","receduc3","qd2aos","raceos"))

dta80$DATE <- as.numeric(dta80$DATE)

dta80$MALE <- 1*(dta80$QD1==1)

dta80$HEALTH <- NA
dta80$HEALTH[dta80$QD8==1] <- 5
dta80$HEALTH[dta80$QD8==2] <- 4
dta80$HEALTH[dta80$QD8==3] <- 3
dta80$HEALTH[dta80$QD8==4] <- 2
dta80$HEALTH[dta80$QD8==5] <- 1

dta80$INCOME <- NA
dta80$INCOME[dta80$QD17==1] <- 10
dta80$INCOME[dta80$QD17==2] <- 25
dta80$INCOME[dta80$QD17==3] <- 35
dta80$INCOME[dta80$QD17==4] <- 45
dta80$INCOME[dta80$QD17==5] <- 62.5
dta80$INCOME[dta80$QD17==6] <- 82.5
dta80$INCOME[dta80$QD17==7] <- 95
dta80$INCOME[dta80$QD17==8] <- 200

dta80$HISP <- (dta80$QD15==1)*1

dta80$EDUC <- NA
dta80$EDUC[dta80$QD13==1] <- 6
dta80$EDUC[dta80$QD13==2] <- 10
dta80$EDUC[dta80$QD13==3] <- 12
dta80$EDUC[dta80$QD13==4] <- 13
dta80$EDUC[dta80$QD13==5] <- 14
dta80$EDUC[dta80$QD13==6] <- 16
dta80$EDUC[dta80$QD13==7] <- 19

dta80$PID <- NA
dta80$PID[dta80$QD11==2] <- 1
dta80$PID[dta80$QD11 %in% c(3,4,9)] <- 2
dta80$PID[dta80$QD11==1] <- 3

dta80$BETPER <- NA
dta80$BETPER[dta80$Q4A==1] <- 3
dta80$BETPER[dta80$Q4A==4] <- 2
dta80$BETPER[dta80$Q4A==3] <- 2
dta80$BETPER[dta80$Q4A==2] <- 1

dta80$BETCOU <- NA
dta80$BETCOU[dta80$Q4B==1] <- 3
dta80$BETCOU[dta80$Q4B==4] <- 2
dta80$BETCOU[dta80$Q4B==3] <- 2
dta80$BETCOU[dta80$Q4B==2] <- 1

#dta80$QD17
dta80$BLACK <- (dta80$QD16==2)*1
dta80$ASIAN <- (dta80$QD16==3)*1
dta80$OTHER <- (dta80$QD16==4)*1

dta80$COVERED <- (dta80$QD2==1)*1
dta80$HEALTHNOW <- 1*(dta80$Q1==2)

dta80$AGE <- as.numeric(dta80$QD9)
dta80$AGE[dta80$QD9==99] <- NA
dta80$MEDICARE <- (dta80$AGE > 64)*1

dta80$MEDICARESR <- 0
dta80$MEDICARESR <- 1*(dta80$QD2A==3)
dta80$MEDICARESR[dta80$QD2A %in% c(NA)] <- 0

dta80$MEDICAID <- 0
dta80$MEDICAID <- 1*(dta80$QD2A==4)
dta80$MEDICAID[dta80$QD2A %in% c(NA)] <- 0

dta80$IDEO <- NA
#dta80$IDEO[dta80$QD12=="Liberal"] <- 3
#dta80$IDEO[dta80$QD12=="Moderate"] <- 2
#dta80$IDEO[dta80$QD12=="Conservative"] <- 1

dta80$SAWAD <- 1*(dta80$Q14==1)
dta80$SAWADPOS <- 1*(dta80$Q15==1)#"In favor of passing some sort of health care reform this yea")
dta80$SAWADNEG <- 1*(dta80$Q15==2)#"Opposed to passing some sort of health care reform this year")
dta80$SAWADBOTH <- 1*(dta80$Q15==3)#"(VOL.) Have seen both")

dta80$NUMBER <- 80

dta80$MARKET <- NA

dta80$MONTH <- 9

dta80$SELFINSURE <- 0
dta80$SELFINSURE[dta80$QD2A==2]<-1

dta80$EMPLINSURE <- 0
dta80$EMPLINSURE[dta80$QD2A==1]<-1

dta80$PSRAID <- as.numeric(dta80$PSRAID)
dta80$SAMPLE <- as.factor(dta80$SAMPLE)
dta80$AREA <- as.numeric(dta80$AREA)
dta80$STATE <- as.factor(dta80$STATE)
dta80$CREGION <- as.factor(dta80$CREGION)
dta80$DENSITY <- as.numeric(dta80$DENSITY)
dta80$SSTATE <- as.factor(dta80$SSTATE)


dta80$PREEXIST <- NA


#lout80a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta80)
#summary(#lout80a)
##mf80a <- model.frame(#lout80a)

#lout80b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta80)
#summary(#lout80b)
##mf80b <- model.frame(#lout80b)

nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf80a2 <- subsetn(dta80,select=nms)

dta80$FAVOR <- NA
dta80$RETIRED <- NA
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s80 <- subsetn(dta80,select=masterlist, subset=T)



#### SEPTEMBER 2009
dta79 <- read.por.upper("hni079.por",to.data.frame=T)

dta79$MALE <- (dta79$QD1=="Male")*1

dta79$HEALTH <- NA
dta79$HEALTH[dta79$QD8=="Excellent"] <- 5
dta79$HEALTH[dta79$QD8=="Very good"] <- 4
dta79$HEALTH[dta79$QD8=="Good"] <- 3
dta79$HEALTH[dta79$QD8=="Only fair"] <- 2
dta79$HEALTH[dta79$QD8=="Poor"] <- 1

dta79$INCOME <- NA
dta79$INCOME[dta79$QD17=="Less than $20,000"] <- 10
dta79$INCOME[dta79$QD17=="$20,000 to less than $30,000"] <- 25
dta79$INCOME[dta79$QD17=="$30,000 to less than $40,000"] <- 35
dta79$INCOME[dta79$QD17=="$40,000 to less than $50,000"] <- 45
dta79$INCOME[dta79$QD17=="$50,000 to less than $75,000"] <- 62.5
dta79$INCOME[dta79$QD17=="$75,000 to less than $90,000"] <- 82.5
dta79$INCOME[dta79$QD17=="$90,000 to less than $100,000"] <- 95
dta79$INCOME[dta79$QD17=="$100,000 or more"] <- 200

dta79$HISP <- (dta79$QD15=="Yes")*1

dta79$EDUC <- NA
dta79$EDUC[dta79$QD13=="None, or grade 1-8"] <- 6
dta79$EDUC[dta79$QD13=="High school incomplete (grades 9-11)"] <- 10
dta79$EDUC[dta79$QD13=="High school graduate (grade 12 or GED certificate)"] <- 12
dta79$EDUC[dta79$QD13=="Technical, trade or vocational school AFTER high school"] <- 13
dta79$EDUC[dta79$QD13=="Some college, no four-year degree (includes associate degree"] <- 14
dta79$EDUC[dta79$QD13=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta79$EDUC[dta79$QD13=="Post-graduate or professional schooling after college (e.g.,"] <- 19

dta79$PID <- NA
dta79$PID[dta79$QD11=="Democrat"] <- 1
dta79$PID[dta79$QD11 %in% c("Independent","Or what?")] <- 2
dta79$PID[dta79$QD11=="Republican"] <- 3

dta79$BETPER <- NA
dta79$BETPER[dta79$Q4A=="Better off"] <- 3
dta79$BETPER[dta79$Q4A=="(VOL.) It depends"] <- 2
dta79$BETPER[dta79$Q4A=="Wouldn"] <- 2
dta79$BETPER[dta79$Q4A=="Worse off"] <- 1

dta79$BETCOU <- NA
dta79$BETCOU[dta79$Q4B=="Better off"] <- 3
dta79$BETCOU[dta79$Q4B=="(VOL.) It depends"] <- 2
dta79$BETCOU[dta79$Q4B=="Wouldn"] <- 2
dta79$BETCOU[dta79$Q4B=="Worse off"] <- 1

#dta79$QD17
dta79$BLACK <- (dta79$QD16=="Black or African-American")*1
dta79$ASIAN <- (dta79$QD16=="Asian")*1
dta79$OTHER <- (dta79$QD16=="Other or mixed race (SPECIFY)")*1

dta79$PREEXIST <- (dta79$QD8A=="Yes")*1
dta79$COVERED <- (dta79$QD2=="Covered by health insurance")*1
dta79$HEALTHNOW <- 1*(dta79$Q1=="It is more important than ever to take on health care reform")

dta79$AGE <- dta79$QD9
dta79$AGE[dta79$QD9==99] <- NA
dta79$MEDICARE <- (dta79$AGE > 64)*1

dta79$MEDICARESR <- 0
dta79$MEDICARESR <- 1*(dta79$QD2A=="Medicare")
dta79$MEDICARESR[dta79$QD2A %in% c(NA)] <- 0

dta79$MEDICAID <- 0
dta79$MEDICAID <- 1*(dta79$QD2A=="Medicaid/Medi-CAL")
dta79$MEDICAID[dta79$QD2A %in% c(NA)] <- 0

dta79$IDEO <- NA
dta79$IDEO[dta79$QD12=="Liberal"] <- 3
dta79$IDEO[dta79$QD12=="Moderate"] <- 2
dta79$IDEO[dta79$QD12=="Conservative"] <- 1

dta79$SAWAD <- 1*(dta79$Q12=="Yes")
dta79$SAWADPOS <- 1*(dta79$Q13=="In favor of passing some sort of health care reform this yea")
dta79$SAWADNEG <- 1*(dta79$Q13=="Opposed to passing some sort of health care reform this year")
dta79$SAWADBOTH <- 1*(dta79$Q13=="(VOL.) Have seen both")

dta79$NUMBER <- 79

dta79$MARKET <- NA

dta79$MONTH <- 8

dta79$SELFINSURE <- 0
dta79$SELFINSURE[dta79$QD2A=="Plan you purchased yourself"]<-1

dta79$EMPLINSURE <- 0
dta79$EMPLINSURE[dta79$QD2A=="Plan through your/your spouse"]<-1

#lout79a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta79)
#summary(#lout79a)
##mf79a <- model.frame(#lout79a)

#lout79b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta79)
#summary(#lout79b)
##mf79b <- model.frame(#lout79b)

dta79$SSTATE <- dta79$STATE
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf79a2 <- subsetn(dta79,select=nms)



#lout79c <- glm(HEALTHNOW ~ MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta79)
#summary(#lout79c)
##mf79 <- model.frame(#lout79c)

dta79$FAVOR <- NA
dta79$RETIRED <- NA
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s79 <- subsetn(dta79,select=masterlist, subset=T)

############ AUGUST 2009
#C:/Users/dh335/Documents/healthcare/
load("hni078.Rdata")
dta78 <- dta
rm(dta)

dta78$MALE <- 1*(dta78$QD1=="Male")

dta78$HEALTH <- NA
dta78$HEALTH[dta78$QD4=="Excellent"] <- 5
dta78$HEALTH[dta78$QD4=="Very good"] <- 4
dta78$HEALTH[dta78$QD4=="Good"] <- 3
dta78$HEALTH[dta78$QD4=="Only fair"] <- 2
dta78$HEALTH[dta78$QD4=="Poor"] <- 1

dta78$INCOME <- NA
dta78$INCOME[dta78$QD13=="Less than $20,000"] <- 10
dta78$INCOME[dta78$QD13=="$20,000 to less than $30,000"] <- 25
dta78$INCOME[dta78$QD13=="$30,000 to less than $40,000"] <- 35
dta78$INCOME[dta78$QD13=="$40,000 to less than $50,000"] <- 45
dta78$INCOME[dta78$QD13=="$50,000 to less than $75,000"] <- 62.5
dta78$INCOME[dta78$QD13=="$75,000 to less than $90,000"] <- 82.5
dta78$INCOME[dta78$QD13=="$90,000 to less than $100,000"] <- 95
dta78$INCOME[dta78$QD13=="$100,000 or more"] <- 200

dta78$HISP <- (dta78$QD11=="Yes")*1

dta78$EDUC <- NA
dta78$EDUC[dta78$QD9=="None, or grade 1-8"] <- 6
dta78$EDUC[dta78$QD9=="High school incomplete (grades 9-11)"] <- 10
dta78$EDUC[dta78$QD9=="High school graduate (grade 12 or GED certificate)"] <- 12
dta78$EDUC[dta78$QD9=="Technical, trade or vocational school AFTER high school"] <- 13
dta78$EDUC[dta78$QD9=="Some college, no four-year degree (includes associate degree"] <- 14
dta78$EDUC[dta78$QD9=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta78$EDUC[dta78$QD9=="Post-graduate or professional schooling after college (e.g.,"] <- 19

dta78$PID <- NA
dta78$PID[dta78$QD7=="Democrat"] <- 1
dta78$PID[dta78$QD7 %in% c("Independent","Or what?")] <- 2
dta78$PID[dta78$QD7=="Republican"] <- 3

dta78$BETPER <- NA
dta78$BETPER[dta78$Q3A=="Better off"] <- 3
dta78$BETPER[dta78$Q3A=="(VOL.) It depends"] <- 2
dta78$BETPER[dta78$Q3A=="Wouldn"] <- 2
dta78$BETPER[dta78$Q3A=="Worse off"] <- 1

dta78$BETCOU <- NA
dta78$BETCOU[dta78$Q3B=="Better off"] <- 3
dta78$BETCOU[dta78$Q3B=="(VOL.) It depends"] <- 2
dta78$BETCOU[dta78$Q3B=="Wouldn"] <- 2
dta78$BETCOU[dta78$Q3B=="Worse off"] <- 1

dta78$BETMED <- NA
dta78$BETMED[dta78$Q3C=="Better off"] <- 3
dta78$BETMED[dta78$Q3C=="(VOL.) It depends"] <- 2
dta78$BETMED[dta78$Q3C=="Wouldn"] <- 2
dta78$BETMED[dta78$Q3C=="Worse off"] <- 1

dta78$AGE <- dta78$QD5
dta78$AGE[dta78$QD5==99] <- NA
dta78$MEDICARE <- (dta78$AGE > 64)*1

dta78$IDEO <- NA
dta78$IDEO[dta78$QD8=="Liberal"] <- 3
dta78$IDEO[dta78$QD8=="Moderate"] <- 2
dta78$IDEO[dta78$QD8=="Conservative"] <- 1

#dta78$QD17
dta78$BLACK <- (dta78$QD12=="Black or African-American")*1
dta78$ASIAN <- (dta78$QD12=="Asian")*1
dta78$OTHER <- (dta78$QD12=="Other or mixed race (SPECIFY)")*1

dta78$MEDICARE <- (dta78$AGE > 64)*1
#dta78$PREEXIST <- (dta78$QD8A=="Yes")*1
dta78$COVERED <- (dta78$QD2=="Covered by health insurance")*1
dta78$HEALTHNOW <- 1*(dta78$Q1=="It is more important than ever to take on health care reform")

dta78$MEDICARESR <- 0
dta78$MEDICARESR <- 1*(dta78$QD2A=="Medicare")
dta78$MEDICARESR[dta78$QD2A %in% c(NA)] <- 0

dta78$MEDICAID <- 0
dta78$MEDICAID <- 1*(dta78$QD2A=="Medicaid/Medi-CAL")
dta78$MEDICAID[dta78$QD2A %in% c(NA)] <- 0

dta78$SAWAD <- 1*(dta78$Q10=="Yes")
dta78$SAWADPOS <- 1*(dta78$Q11=="In favor of passing some sort of health care reform this yea")
dta78$SAWADNEG <- 1*(dta78$Q11=="Opposed to passing some sort of health care reform this year")
dta78$SAWADBOTH <- 1*(dta78$Q11=="(VOL.) Have seen both")

dta78$NUMBER <- 78

dta78$MARKET <- NA

dta78$MONTH <- 7

dta78$SELFINSURE <- 0
dta78$SELFINSURE[dta78$QD2A=="Plan you purchased yourself"]<-1

dta78$EMPLINSURE <- 0
dta78$EMPLINSURE[dta78$QD2A=="Plan through your/your spouse"]<-1

dta78$PREEXIST <- NA

#lout78a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta78)
#summary(#lout78a)
##mf78a <- model.frame(#lout78a)

#lout78b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta78)
#summary(#lout78b)
##mf78b <- model.frame(#lout78b)

dta78$SSTATE <- dta78$SAMPST
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf78a2 <- subsetn(dta78,select=nms)


#lout78c <- glm(HEALTHNOW ~ MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta78)
#summary(#lout78c)
##mf78 <- model.frame(#lout78c)

dta78$FAVOR <- NA
dta78$RETIRED <- NA
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s78 <- subsetn(dta78,select=masterlist, subset=T)

############## JULY 2009
dta77 <-  read.por.upper("hni077.por",to.data.frame=T)

dta77$MALE <- 1*(dta77$D1=="Male")

dta77$HEALTH <- NA
dta77$HEALTH[dta77$QD4=="Excellent"] <- 5
dta77$HEALTH[dta77$QD4=="Very good"] <- 4
dta77$HEALTH[dta77$QD4=="Good"] <- 3
dta77$HEALTH[dta77$QD4=="Only fair"] <- 2
dta77$HEALTH[dta77$QD4=="Poor"] <- 1

dta77$INCOME <- NA
dta77$INCOME[dta77$QD13=="Less than $20,000"] <- 10
dta77$INCOME[dta77$QD13=="$20,000 to less than $30,000"] <- 25
dta77$INCOME[dta77$QD13=="$30,000 to less than $40,000"] <- 35
dta77$INCOME[dta77$QD13=="$40,000 to less than $50,000"] <- 45
dta77$INCOME[dta77$QD13=="$50,000 to less than $75,000"] <- 62.5
dta77$INCOME[dta77$QD13=="$75,000 to less than $90,000"] <- 82.5
dta77$INCOME[dta77$QD13=="$90,000 to less than $100,000"] <- 95
dta77$INCOME[dta77$QD13=="$100,000 or more"] <- 200

dta77$HISP <- (dta77$QD11=="Yes")*1

dta77$AGE2 <- dta77$AGE
dta77$AGE[dta77$AGE2==99] <- NA
dta77$MEDICARE <- (dta77$AGE > 64)*1

dta77$EDUC <- NA
dta77$EDUC[dta77$QD9=="None, or grade 1-8"] <- 6
dta77$EDUC[dta77$QD9=="High school incomplete (grades 9-11)"] <- 10
dta77$EDUC[dta77$QD9=="High school graduate (grade 12 or GED certificate)"] <- 12
dta77$EDUC[dta77$QD9=="Technical, trade or vocational school AFTER high school"] <- 13
dta77$EDUC[dta77$QD9=="Some college, no four-year degree (includes associate degree)"] <- 14
dta77$EDUC[dta77$QD9=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta77$EDUC[dta77$QD9=="Post-graduate or professional schooling after college (e.g., toward a Master's degree or Ph.D; law or medical school)"] <- 19

dta77$PID <- NA
dta77$PID[dta77$QD7=="Democrat"] <- 1
dta77$PID[dta77$QD7 %in% c("Independent","Or what?")] <- 2
dta77$PID[dta77$QD7=="Republican"] <- 3

dta77$BETPER <- NA
dta77$BETPER[dta77$Q5A=="Better off"] <- 3
dta77$BETPER[dta77$Q5A=="(VOL.) It depends"] <- 2
dta77$BETPER[dta77$Q5A=="Wouldn"] <- 2
dta77$BETPER[dta77$Q5A=="Worse off"] <- 1

dta77$BETCOU <- NA
dta77$BETCOU[dta77$Q5B=="Better off"] <- 3
dta77$BETCOU[dta77$Q5B=="(VOL.) It depends"] <- 2
dta77$BETCOU[dta77$Q5B=="Wouldn"] <- 2
dta77$BETCOU[dta77$Q5B=="Worse off"] <- 1

#dta77$QD17
dta77$BLACK <- (dta77$QD12=="Black or African-American")*1
dta77$ASIAN <- (dta77$QD12=="Asian")*1
dta77$OTHER <- (dta77$QD12=="Other or mixed race (SPECIFY)")*1


#dta77$PREEXIST <- (dta77$QD8A=="Yes")*1
dta77$COVERED <- (dta77$QD2=="Covered by health insurance")*1
dta77$HEALTHNOW <- 1*(dta77$Q3=="It is more important than ever to take on health care reform now")

dta77$MEDICARESR <- 0
dta77$MEDICARESR <- 1*(dta77$QD2A=="Medicare")
dta77$MEDICARESR[dta77$QD2A %in% c(NA)] <- 0

dta77$MEDICAID <- 0
dta77$MEDICAID <- 1*(dta77$QD2A=="Medicaid/Medi-CAL")
dta77$MEDICAID[dta77$QD2A %in% c(NA)] <- 0

dta77$IDEO <- NA
dta77$IDEO[dta77$QD8=="Liberal"] <- 3
dta77$IDEO[dta77$QD8=="Moderate"] <- 2
dta77$IDEO[dta77$QD8=="Conservative"] <- 1

dta77$SAWAD <- 1*(dta77$Q11=="Yes")
dta77$SAWADPOS <- 1*(dta77$Q12=="In favor of passing some sort of health care reform this year")
dta77$SAWADNEG <- 1*(dta77$Q12=="Opposed to passing some sort of health care reform this year")
dta77$SAWADBOTH <- NA

dta77$NUMBER <- 77

dta77$MARKET <- NA

dta77$MONTH <- 6

dta77$SELFINSURE <- 0
dta77$SELFINSURE[dta77$QD2A=="Plan you purchased yourself"]<-1

dta77$EMPLINSURE <- 0
dta77$EMPLINSURE[dta77$QD2A=="Plan through your/your spouse"]<-1

dta77$PREEXIST <- NA

#lout77a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta77)
#summary(#lout77a)
##mf77a <- model.frame(#lout77a)

#lout77b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta77)
#summary(#lout77b)
##mf77b <- model.frame(#lout77b)
names(dta77)[130] <- "SSTATE"
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf77a2 <- subsetn(dta77,select=nms)

#lout77c <- glm(HEALTHNOW ~ MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta77)
#summary(#lout77c)
##mf77 <- model.frame(#lout77c)

dta77$FAVOR <- NA
dta77$RETIRED <- NA
dta77$SSTATE <- dta77$FSTATE
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s77 <- subsetn(dta77,select=masterlist, subset=T)

######## JUNE 2009
wds <- c(5,1,4,3,1,1,2,rep(1,41),rep(1,42),2,rep(1,10),rep(1,8),2,2,6,3,2,1,1,2,rep(1,8),4,5,4,5,5,40,40)
dta76 <- read.fwf("hni076.dat",widths=wds)#
#dta76 <- NULL
cn <- c("psraid","sample","date","area","tz","scregion","sampst","usr","oldusrl","form","lang","qs1","d1","q1")
cn1 <- c("q2a","q2b","q2c","q2d","q2e","q2f","q2g","q2h","q3","q4a","q4b","q5","q6","q7","q8a","q8b","q8c","q8d","q8e","q8f","q8g","q8h","q9a","q9b","q9c","q9d","q9e","q9f","q9g","q9h")
cn2 <- c("q10","q11","q12","q13","q14","q14a","q14b","q15a","q15b","q15c","q15d","q15e","q15f","q16","q17","q18","q19","q20","q21")
cn3 <- c("q22a","q22b","q23a","q23b","d2","d2a","q24","q25a","q25b","q25c","q25d","q25e","q25f","q25g","q25h","q25i","q25j","q25k","q26","q27a","q27b","q27c","q27d","q27e","q27f","q27g","d3","d4","d4a")
cn4 <- c("d5","d6","d7","d8","d9","d10","d11","d12","d13")
cn5 <- c("l1","l2","c1","c2","hh1","int1","recage2","money","q25cnt","q27cnt","stalph","AC","state","cregion","density3","fstate","fcregion","sdensity3","rbcounty","usr1","phoneuse","recage","receduc","racethn","wt1","weight","psa","wt1a","weight2","qd2aos","raceos")

identical(length(wds),length(c(cn,cn1,cn2,cn3,cn4,cn5)))

colnames(dta76) <- toupper(c(cn,cn1,cn2,cn3,cn4,cn5))

dta76$DATE <- as.numeric(dta76$DATE)

dta76$MALE <- 1*(dta76$D1==1)

dta76$HEALTH <- NA
dta76$HEALTH[dta76$D3==1] <- 5
dta76$HEALTH[dta76$D3==2] <- 4
dta76$HEALTH[dta76$D3==3] <- 3
dta76$HEALTH[dta76$D3==4] <- 2
dta76$HEALTH[dta76$D3==5] <- 1

dta76$INCOME <- NA
dta76$INCOME[dta76$D13==1] <- 10
dta76$INCOME[dta76$D13==2] <- 25
dta76$INCOME[dta76$D13==3] <- 35
dta76$INCOME[dta76$D13==4] <- 45
dta76$INCOME[dta76$D13==5] <- 62.5
dta76$INCOME[dta76$D13==6] <- 82.5
dta76$INCOME[dta76$D13==7] <- 95
dta76$INCOME[dta76$D13==8] <- 200

dta76$HISP <- (dta76$D11==1)*1

dta76$AGE <- dta76$D4
dta76$AGE[dta76$D4==99] <- NA
dta76$MEDICARE <- (dta76$AGE > 64)*1

dta76$EDUC <- NA
dta76$EDUC[dta76$D8==1] <- 6
dta76$EDUC[dta76$D8==2] <- 10
dta76$EDUC[dta76$D8==3] <- 12
dta76$EDUC[dta76$D8==4] <- 13
dta76$EDUC[dta76$D8==5] <- 14
dta76$EDUC[dta76$D8==6] <- 16
dta76$EDUC[dta76$D8==7] <- 19

dta76$PID <- NA
dta76$PID[dta76$D6==2] <- 1
dta76$PID[dta76$D6 %in% c(3,4,9)] <- 2
dta76$PID[dta76$D6==1] <- 3

dta76$BETPER <- NA
dta76$BETPER[dta76$Q4A==1] <- 3
dta76$BETPER[dta76$Q4A==4] <- 2
dta76$BETPER[dta76$Q4A==3] <- 2
dta76$BETPER[dta76$Q4A==2] <- 1

dta76$BETCOU <- NA
dta76$BETCOU[dta76$Q4B==1] <- 3
dta76$BETCOU[dta76$Q4B==4] <- 2
dta76$BETCOU[dta76$Q4B==3] <- 2
dta76$BETCOU[dta76$Q4B==2] <- 1

#dta76$QD17
dta76$BLACK <- (dta76$D12==2)*1
dta76$ASIAN <- (dta76$D12==3)*1
dta76$OTHER <- (dta76$D12==4)*1

dta76$COVERED <- (dta76$D2==1)*1
dta76$HEALTHNOW <- 1*(dta76$Q3==2)

dta76$MEDICARESR <- 0
dta76$MEDICARESR <- 1*(dta76$D2A==3)
dta76$MEDICARESR[dta76$D2A %in% c(NA)] <- 0

dta76$MEDICAID <- 0
dta76$MEDICAID <- 1*(dta76$D2A==4)
dta76$MEDICAID[dta76$D2A %in% c(9)] <- 0
dta76$MEDICAID[dta76$D2A %in% c(NA)] <- 0

dta76$IDEO <- NA
dta76$IDEO[dta76$D7==1] <- 3
dta76$IDEO[dta76$D7==2] <- 2
dta76$IDEO[dta76$D7==3] <- 1

dta76$SAWAD <- 1*(dta76$Q14==1)
dta76$SAWADPOS <- 1*(dta76$Q12==1)
dta76$SAWADNEG <- 1*(dta76$Q12==2)
dta76$SAWADBOTH <- NA

dta76$NUMBER <- 76

dta76$MARKET <- NA

dta76$MONTH <-5

dta76$SELFINSURE <- 0
dta76$SELFINSURE[dta76$D2A==2]<-1

dta76$EMPLINSURE <- 0
dta76$EMPLINSURE[dta76$D2A==1]<-1

dta76$PREEXIST <- NA

#lout76a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta76)
#summary(#lout76a)
##mf76a <- model.frame(#lout76a)

#lout76b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta76)
#summary(#lout76b)
##mf76b <- model.frame(#lout76b)

names(dta76)[which(names(dta76)=="SAMPST")] <- "SSTATE"
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf76a2 <- subsetn(dta76,select=nms)

dta76$FAVOR <- NA
dta76$RETIRED <- NA
#dta76$SSTATE <- dta76$STATE
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s76 <- subsetn(dta76,select=masterlist, subset=T)

#### APRIL 2009
#dta75 <- read.por.upper("hni075.por",to.data.frame=T)
dta75 <- read.csv.lower("hni075.csv")

dta75$MALE <- 1*(dta75$q1==1)

dta75$HEALTH <- NA
dta75$HEALTH[dta75$d3==1] <- 5
dta75$HEALTH[dta75$d3==2] <- 4
dta75$HEALTH[dta75$d3==3] <- 3
dta75$HEALTH[dta75$d3==4] <- 2
dta75$HEALTH[dta75$d3==5] <- 1

dta75$INCOME <- NA
dta75$INCOME[dta75$d11==1] <- 10
dta75$INCOME[dta75$d11==2] <- 25
dta75$INCOME[dta75$d11==3] <- 40
dta75$INCOME[dta75$d11==4] <- 62.5
dta75$INCOME[dta75$d11==5] <- 87.5
dta75$INCOME[dta75$d11==6] <- 200

dta75$HISP <- (dta75$d9==1)*1

dta75$EDUC <- NA
dta75$EDUC[dta75$d8==1] <- 6
dta75$EDUC[dta75$d8==2] <- 10
dta75$EDUC[dta75$d8==3] <- 12
dta75$EDUC[dta75$d8==4] <- 13
dta75$EDUC[dta75$d8==5] <- 14
dta75$EDUC[dta75$d8==6] <- 16
dta75$EDUC[dta75$d8==7] <- 19

dta75$PID <- NA
dta75$PID[dta75$d6==2] <- 1
dta75$PID[dta75$d6 %in% c(3,4)] <- 2
dta75$PID[dta75$d6==1] <- 3

dta75$BETPER <- NA
dta75$BETPER[dta75$q5a==1] <- 3
dta75$BETPER[dta75$q5a==4] <- 2
dta75$BETPER[dta75$q5a==3] <- 2
dta75$BETPER[dta75$q5a==2] <- 1

dta75$BETCOU <- NA
dta75$BETCOU[dta75$q5b==1] <- 3
dta75$BETCOU[dta75$q5b==4] <- 2
dta75$BETCOU[dta75$q5b==3] <- 2
dta75$BETCOU[dta75$q5b==2] <- 1

dta75$BLACK <- (dta75$d10==2)*1
dta75$ASIAN <- (dta75$d10==3)*1
dta75$OTHER <- (dta75$d10==4)*1

dta75$AGE <- dta75$d4
dta75$AGE[dta75$d4==99] <- NA

dta75$MEDICARE <- (dta75$AGE > 64)*1
#dta76$PREEXIST <- (dta76$QD8A=="Yes")*1
dta75$COVERED <- (dta75$qd2==1)*1

dta75$MEDICARESR <- 0
dta75$MEDICARESR <- 1*(dta75$qd2a==3)
dta75$MEDICARESR[dta75$qd2a %in% c(NA)] <- 0

dta75$MEDICAID <- 0
dta75$MEDICAID <- 1*(dta75$qd2a==4)
dta75$MEDICAID[dta75$qd2a %in% c(NA)] <- 0

dta75$IDEO <- NA
dta75$IDEO[dta75$d7==1] <- 3
dta75$IDEO[dta75$d7==2] <- 2
dta75$IDEO[dta75$d7==3] <- 1

dta75$SAWAD <- NA
dta75$SAWADPOS <- NA
dta75$SAWADNEG <- NA
dta75$SAWADBOTH <- NA

dta75$NUMBER <- 75

dta75$MARKET <- NA

dta75$MONTH <- 3

dta75$SELFINSURE <- 0
dta75$SELFINSURE[dta75$qd2a==2]<-1

dta75$EMPLINSURE <- 0
dta75$EMPLINSURE[dta75$qd2a==1]<-1

dta75$PREEXIST <- NA

#lout75a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta75)
#summary(#lout75a)
##mf75a <- model.frame(#lout75a)

#lout75b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta75)
#summary(#lout75b)
##mf75b <- model.frame(#lout75b)

###lout75d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta74)
##summary(#lout75d)
###fv75a <- model.frame(#lout75d)

names(dta75)[142] <- "SSTATE"
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf75a2 <- subsetn(dta75,select=nms)

dta75$FAVOR <- NA
dta75$RETIRED <- NA
#colnames(dta75)[1] <- "PSRAID"
dta75$PSRAID <- dta75$psraid
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s75 <- subsetn(dta75,select=masterlist, subset=T)

##### FEBRUARY 09
dta74 <- read.por.upper("hni074.por",to.data.frame=T)

dta74$MALE <- 1*(dta74$SEX=="Male")

dta74$HEALTH <- NA
dta74$HEALTH[dta74$QD5=="Excellent"] <- 5
dta74$HEALTH[dta74$QD5=="Very good "] <- 4
dta74$HEALTH[dta74$QD5=="Good"] <- 3
dta74$HEALTH[dta74$QD5=="Only fair"] <- 2
dta74$HEALTH[dta74$QD5=="Poor"] <- 1

dta74$INCOME <- NA
dta74$INCOME[dta74$QD15=="Less than $20,000"] <- 10
dta74$INCOME[dta74$QD15=="$20,000 to less than $30,000"] <- 25
dta74$INCOME[dta74$QD15=="$30,000 to less than $50,000"] <- 40
dta74$INCOME[dta74$QD15=="$50,000 to less than $75,000"] <- 62.5
dta74$INCOME[dta74$QD15=="$75,000 to less than $100,000"] <- 87.5
dta74$INCOME[dta74$QD15=="$100,000 or more"] <- 200

dta74$HISP <- (dta74$QD13=="Yes")*1

dta74$EDUC <- NA
dta74$EDUC[dta74$QD12=="None, or grade 1-8"] <- 6
dta74$EDUC[dta74$QD12=="High school incomplete (grades 9-11)"] <- 10
dta74$EDUC[dta74$QD12=="High school graduate (grade 12 or GED certificate)"] <- 12
dta74$EDUC[dta74$QD12=="Technical, trade or vocational school AFTER high school"] <- 13
dta74$EDUC[dta74$QD12=="Some college, no four-year degree (includes associate degree)"] <- 14
dta74$EDUC[dta74$QD12=="College graduate (B.S., B.A., or other four-year degree)"] <- 16
dta74$EDUC[dta74$QD12=="Post-graduate or professional schooling after college (e.g., toward a Master's degree or Ph.D; law or medical school)"] <- 19

dta74$PID <- NA
dta74$PID[dta74$QD10=="Democrat "] <- 1
dta74$PID[dta74$QD10 %in% c("Independent","Or what? (INCLUDES 'OTHER' AND 'NONE')")] <- 2
dta74$PID[dta74$QD10=="Republican"] <- 3

dta74$BETPER <- NA
dta74$BETPER[dta74$Q9A=="Better off"] <- 3
dta74$BETPER[dta74$Q9A=="(VOL.) It depends"] <- 2
dta74$BETPER[dta74$Q9A=="Wouldn"] <- 2
dta74$BETPER[dta74$Q9A=="Worse off"] <- 1

dta74$BETCOU <- NA
dta74$BETCOU[dta74$Q9B=="Better off"] <- 3
dta74$BETCOU[dta74$Q9B=="(VOL.) It depends"] <- 2
dta74$BETCOU[dta74$Q9B=="Wouldn"] <- 2
dta74$BETCOU[dta74$Q9B=="Worse off"] <- 1

dta74$BLACK <- (dta74$QD14=="Black or African-American")*1
dta74$ASIAN <- (dta74$QD14=="Asian")*1
dta74$OTHER <- (dta74$QD14=="Other or mixed race (SPECIFY)")*1

dta74$AGE <- dta74$QD8
dta74$AGE[dta74$QD8==99] <- NA

dta74$MEDICARE <- (dta74$AGE > 64)*1
#dta76$PREEXIST <- (dta76$QD8A=="Yes")*1
dta74$COVERED <- (dta74$QD2=="Covered by health insurance")*1

dta74$MEDICARESR <- 0
dta74$MEDICARESR <- 1*(dta74$QD2A=="Medicare")
dta74$MEDICARESR[dta74$QD2A %in% c(NA)] <- 0

dta74$MEDICAID <- 0
dta74$MEDICAID <- 1*(dta74$QD2A=="Medicaid/Medi-CAL")
dta74$MEDICAID[dta74$QD2A %in% c(NA)] <- 0

dta74$IDEO <- NA
dta74$IDEO[dta74$QD11=="Liberal"] <- 3
dta74$IDEO[dta74$QD11=="Moderate"] <- 2
dta74$IDEO[dta74$QD11=="Conservative"] <- 1

dta74$SAWAD <- 1*(dta74$Q8=="Yes")
dta74$SAWADPOS <- NA
dta74$SAWADNEG <- NA
dta74$SAWADBOTH <- NA

dta74$NUMBER <- 74

dta74$MARKET <- NA

dta74$MONTH <- 1

dta74$SELFINSURE <- 0
dta74$SELFINSURE[dta74$QD2A=="Plan you purchased yourself"]<-1

dta74$EMPLINSURE <- 0
dta74$EMPLINSURE[dta74$QD2A=="Plan through your/your spouse"]<-1

dta74$PREEXIST <- NA

#lout74a <- lm(BETPER ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta74)
#summary(#lout74a)
##mf74a <- model.frame(#lout74a)

#lout74b <- lm(BETCOU ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta74)
#summary(#lout74b)
##mf74b <- model.frame(#lout74b)

###lout74d <- lm(FAVOR ~ MEDICAID+MEDICARESR+MEDICARE + AGE+I(AGE^2)+COVERED+INCOME+BLACK+HISP+PID+EDUC, data=dta74)
##summary(#lout74d)
###fv74a <- model.frame(#lout74d)

names(dta74)[6] <- "SSTATE"
nms <- c("RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
#mf74a2 <- subsetn(dta74,select=nms)

dta74$FAVOR <- NA
dta74$RETIRED <- NA
# list <- c("PSRAID","RETIRED","OTHER","PREEXIST","ASIAN","SELFINSURE","EMPLINSURE","MONTH","MARKET","NUMBER","FAVOR","BETCOU","SSTATE","BETPER","MEDICAID","MEDICARESR","MEDICARE","AGE","COVERED","INCOME","BLACK","HISP","PID","EDUC","IDEO","HEALTH","SAWAD","SAWADPOS","SAWADNEG","SAWADBOTH","MALE")
s74 <- subsetn(dta74,select=masterlist, subset=T)

# dates -------------------------------------------------------------------






s74$DATE <- s74$DATE <- "FEB09"
s75$DATE <- s75$DATE <- "APR09"
s76$DATE <- s76$DATE <- "JUN09"
s77$DATE <- s77$DATE <- "JUL09"
s78$DATE <- s78$DATE <- "AUG09"
s79$DATE <- s79$DATE <- "SEP09"
s80$DATE <- s80$DATE <- "OCT09"
s81$DATE <- s81$DATE <- "NOV09"
s82$DATE <- s82$DATE <- "DEC09"
s83$DATE <- s83$DATE <- "JAN10"
s84$DATE <- s84$DATE <- "FEB10"
s85$DATE <- s85$DATE <- "MAR10"
s86$DATE <- s86$DATE <- "APR10"
s87$DATE <- s87$DATE <- "MAY10"
s88$DATE <- s88$DATE <- "JUN10"
s89$DATE <- s89$DATE <- "JUL10"
s90$DATE <- s90$DATE <- "AUG10"
s91$DATE <- s91$DATE <- "SEP10"
s92$DATE <- s92$DATE <- "OCT10"
s93$DATE <- s93$DATE <- "NOV10"
s94$DATE <- s94$DATE <- "DEC10"
s95$DATE <- s95$DATE <- "FEB11"
s96$DATE <- s96$DATE <- "MAR11"
s97$DATE <- s97$DATE <- "APR11"
s98$DATE <- s98$DATE <- "MAY11"
s99$DATE <- s99$DATE <- "JUN11"
s100$DATE <- s100$DATE <- "JUL11"
s101$DATE <- s101$DATE <- "AUG11"
s102$DATE <- s102$DATE <- "SEP11"
s103$DATE <- s103$DATE <- "OCT11"
s104$DATE <- s104$DATE <- "NOV11"
s105$DATE <- s105$DATE <- "DEC11"
s106$DATE <- s106$DATE <- "JAN12"
s107$DATE <- s107$DATE <- "FEB12"
s108$DATE <- s108$DATE <- "MAR12"
s109$DATE <- s109$DATE <- "APR12"
s110$DATE <- s110$DATE <- "MAY12"
s111$DATE <- s111$DATE <- "JUN12"
s112$DATE <- s112$DATE <- "JUL12"
s113$DATE <- s113$DATE <- "AUG12"
s114$DATE <- s114$DATE <- "SEP12"
s115$DATE <- s115$DATE <- "OCT12"
s116$DATE <- s116$DATE <- "NOV12"
s117$DATE <- s117$DATE <- "FEB13"
s118$DATE <- s118$DATE <- "MAR13"
s119$DATE <- s119$DATE <- "APR13"
s120$DATE <- s120$DATE <- "JUN13"
s121$DATE <- s121$DATE <- "AUG13"
s122$DATE <- s122$DATE <- "SEP13"
s123$DATE <- s123$DATE <- "OCT13"
s124$DATE <- s124$DATE <- "NOV13"
s125$DATE <- s125$DATE <- "DEC13"
s126$DATE <- s126$DATE <- "JAN14"
s127$DATE <- s127$DATE <- "FEB14"
s128$DATE <- s128$DATE <- "MAR14"
s129$DATE <- s129$DATE <- "APR14"
s130$DATE <- s130$DATE <- "MAY14"
s131$DATE <- s131$DATE <- "JUN14"
s132$DATE <- s132$DATE <- "JUL14"
s133$DATE <- s133$DATE <- "SEP14"
s134$DATE <- s134$DATE <- "OCT14"
s135$DATE <- s135$DATE <- "NOV14"
s136$DATE <- s136$DATE <- "DEC14"
s137$DATE <- s137$DATE <- "JAN15"
s138$DATE <- s138$DATE <- "MAR15"
s139$DATE <- s139$DATE <- "MAY15"
s140$DATE <- s140$DATE <- "JUN15"
s141$DATE <- s141$DATE <- "JUL15"
s142$DATE <- s142$DATE <- "AUG15"
s143$DATE <- s143$DATE <- "SEP15"
s144$DATE <- s144$DATE <- "OCT15"
s145$DATE <- s145$DATE <- "NOV15"
s146$DATE <- s146$DATE <- "DEC15"
s147$DATE <- s147$DATE <- "JAN16"

s148$DATE <- "FEB16"
s149$DATE <- "MAR16"

s150$DATE <- "APR16"
s151$DATE <- "JUN16"
s152$DATE <- "JUL16"
s153$DATE <- "AUG16"
s154$DATE <- "SEP16"
s155$DATE <- "OCT16"
s156$DATE <- "NOV16"
s157$DATE <- "DEC16"
### missing ID for s158
s158$DATE <- "FEB17"
s159$DATE <- "MAR17"
s160$DATE <- "APR17"

s161$DATE <- "MAY17"
s162$DATE <- "JUN17"
s163$DATE <- "JUL17"

s164$DATE <- "AUG17"
s165$DATE <- "SEP17"


s74$DATN <- s74$DATN <- 2
s75$DATN <- s75$DATN <- 4
s76$DATN <- s76$DATN <- 6
s77$DATN <- s77$DATN <- 7
s78$DATN <- s78$DATN <- 8
s79$DATN <- s79$DATN <- 9
s80$DATN <- s80$DATN <- 10
s81$DATN <- s81$DATN <- 11
s82$DATN <- s82$DATN <- 12
s83$DATN <- s83$DATN <- 13
s84$DATN <- s84$DATN <- 14
s85$DATN <- s85$DATN <- 15
s86$DATN <- s86$DATN <- 16
s87$DATN <- s87$DATN <- 17
s88$DATN <- s88$DATN <- 18
s89$DATN <- s89$DATN <- 19
s90$DATN <- s90$DATN <- 20
s91$DATN <- s91$DATN <- 21
s92$DATN <- s92$DATN <- 22
s93$DATN <- s93$DATN <- 23
s94$DATN <- s94$DATN <- 24
s95$DATN <- s95$DATN <- 26
s96$DATN <- s96$DATN <- 27
s97$DATN <- s97$DATN <- 28
s98$DATN <- s98$DATN <- 29
s99$DATN <- s99$DATN <- 30
s100$DATN <- s100$DATN <- 31
s101$DATN <- s101$DATN <- 32
s102$DATN <- s102$DATN <- 33
s103$DATN <- s103$DATN <- 34
s104$DATN <- s104$DATN <- 35
s105$DATN <- s105$DATN <- 36
s106$DATN <- s106$DATN <- 37
s107$DATN <- s107$DATN <- 38
s108$DATN <- s108$DATN <- 39
s109$DATN <- s109$DATN <- 40
s110$DATN <- s110$DATN <- 41
s111$DATN <- s111$DATN <- 42
s112$DATN <- s112$DATN <- 43
s113$DATN <- s113$DATN <- 44
s114$DATN <- s114$DATN <- 45
s115$DATN <- s115$DATN <- 46
s116$DATN <- s116$DATN <- 47
s117$DATN <- s117$DATN <- 50
s118$DATN <- s118$DATN <- 51
s119$DATN <- s119$DATN <- 52
s120$DATN <- s120$DATN <- 54
s121$DATN <- s121$DATN <- 56
s122$DATN <- s122$DATN <- 57
s123$DATN <- s123$DATN <- 58
s124$DATN <- s124$DATN <- 59
s125$DATN <- s125$DATN <- 60
s126$DATN <- s126$DATN <- 61
s127$DATN <- s127$DATN <- 62
s128$DATN <- s128$DATN <- 63
s129$DATN <- s129$DATN <- 64
s130$DATN <- s130$DATN <- 65
s131$DATN <- s131$DATN <- 66
s132$DATN <- s132$DATN <- 67
s133$DATN <- s133$DATN <- 69
s134$DATN <- s134$DATN <- 70
s135$DATN <- s135$DATN <- 71
s136$DATN <- s136$DATN <- 72
s137$DATN <- s137$DATN <- 73
s138$DATN <- s138$DATN <- 75
s139$DATN <- s139$DATN <- 77
s140$DATN <- s140$DATN <- 78
s141$DATN <- s141$DATN <- 79
s142$DATN <- s142$DATN <- 80
s143$DATN <- s143$DATN <- 81
s144$DATN <- s144$DATN <- 82
s145$DATN <- s145$DATN <- 83
s146$DATN <- s146$DATN <- 84
s147$DATN <- s147$DATN <- 85

s147$DATN <- s147$DATN <- 86
s148$DATN <- s148$DATN <- 87
s149$DATN <- s149$DATN <- 88
s150$DATN <- s150$DATN <- 89
s151$DATN <- s151$DATN <- 90
s152$DATN <- s152$DATN <- 91
s153$DATN <- s153$DATN <- 92
s154$DATN <- s154$DATN <- 93
s155$DATN <- s155$DATN <- 94

s156$DATN <- s156$DATN <- 95
s157$DATN <- s157$DATN <- 96

s158$DATN <- s158$DATN <- 97
s159$DATN <- s159$DATN <- 99
s160$DATN <- s160$DATN <- 100

s161$DATN <- s161$DATN <- 101
s162$DATN <- s162$DATN <- 102
s163$DATN <- s163$DATN <- 103
s164$DATN <- s164$DATN <- 104
s165$DATN <- s165$DATN <- 105


# combining and saving data ----------------------------------------------------------

#COMBOING DATA
sdat <- rbind(s74,s75,s76,s77,s78,
                 s79,s80,s81,s82,s83,s84,s85,s86,s87,s88,
                 s89,s90,s91,s92,s93,s94,
                 s95,s96,s97,s98,s99,s100,
                 s101,s102,s103,s104,s105,s106,
                 s107,s108,s109,s110,s111,s112,
                 s113,s114,s115,s116,s117,s118,
                 s119,s120,s121,s122,s123,s124,
                 s125,s126,s127,s128,s129,s130,
                 s131,s132,s133,s134,s135,s136,
                 s137,s138,s139,s140,s141,s142,s143,
              s144,s145,s146,s147,
		s148,s149,s150,s151,s152,s153,s154,s155,s156,
		s157,s158,s159,s160,s161,s162,s163,s164,s165)

sdat$GOP <- 1*(sdat$PID==3)
sdat$IND <- 1*(sdat$PID==2)


sdat$ST <- NA
sdat$ST[sdat$SSTATE %in% c("alabama","Alabama","1",1)] <- 1
sdat$ST[sdat$SSTATE %in% c("alaska","Alaska","2",2)] <- 2
sdat$ST[sdat$SSTATE %in% c("arizona","Arizona","4",4)] <- 4
sdat$ST[sdat$SSTATE %in% c("arkansas","Arkansas","5",5)] <- 5
sdat$ST[sdat$SSTATE %in% c("california","California","6",6)] <- 6
sdat$ST[sdat$SSTATE %in% c("colorado","Colorado","8",8)] <- 8
sdat$ST[sdat$SSTATE %in% c("connecticut","Connecticut","9",9)] <- 9
sdat$ST[sdat$SSTATE %in% c("delaware","Delaware","10",10)] <- 10
sdat$ST[sdat$SSTATE %in% c("district of columbia","District of Columbia","11",11)] <- 11
sdat$ST[sdat$SSTATE %in% c("florida","Florida","12",12)] <- 12
sdat$ST[sdat$SSTATE %in% c("georgia","Georgia","13",13)] <- 13
sdat$ST[sdat$SSTATE %in% c("hawaii","Hawaii","15",15)] <- 15
sdat$ST[sdat$SSTATE %in% c("idaho","Idaho","16",16)] <- 16
sdat$ST[sdat$SSTATE %in% c("illinois","Illinois","17",17)] <- 17
sdat$ST[sdat$SSTATE %in% c("indiana","Indiana","18",18)] <- 18
sdat$ST[sdat$SSTATE %in% c("iowa","Iowa","19",19)] <- 19
sdat$ST[sdat$SSTATE %in% c("kansas","Kansas","20",20)] <- 20
sdat$ST[sdat$SSTATE %in% c("kentucky","Kentucky","21",21)] <- 21
sdat$ST[sdat$SSTATE %in% c("louisiana","Louisiana","22",22)] <- 22
sdat$ST[sdat$SSTATE %in% c("maine","Maine","23",23)] <- 23
sdat$ST[sdat$SSTATE %in% c("maryland","Maryland","24",24)] <- 24
sdat$ST[sdat$SSTATE %in% c("massachusetts","Massachusetts","25",25)] <- 25
sdat$ST[sdat$SSTATE %in% c("michigan","Michigan","26",26)] <- 26
sdat$ST[sdat$SSTATE %in% c("minnesota","Minnesota","27",27)] <- 27
sdat$ST[sdat$SSTATE %in% c("mississippi","Mississippi","28",28)] <- 28
sdat$ST[sdat$SSTATE %in% c("missouri","Missouri","29",29)] <- 29
sdat$ST[sdat$SSTATE %in% c("montana","Montana","30",30)] <- 30
sdat$ST[sdat$SSTATE %in% c("nebraska","Nebraska","31",31)] <- 31
sdat$ST[sdat$SSTATE %in% c("nevada","Nevada","32",32)] <- 32
sdat$ST[sdat$SSTATE %in% c("new hampshire","New Hampshire","33",33)] <- 33
sdat$ST[sdat$SSTATE %in% c("new jersey","New Jersey","34",34)] <- 34
sdat$ST[sdat$SSTATE %in% c("new mexico","New Mexico","35",35)] <- 35
sdat$ST[sdat$SSTATE %in% c("new york","New York","36",36)] <- 36
sdat$ST[sdat$SSTATE %in% c("north carolina","North Carolina","37",37)] <- 37
sdat$ST[sdat$SSTATE %in% c("north dakota","North Dakota","38",38)] <- 38
sdat$ST[sdat$SSTATE %in% c("ohio","Ohio","39",39)] <- 39
sdat$ST[sdat$SSTATE %in% c("Oklahoma","oklahoma","40",40)] <- 40
sdat$ST[sdat$SSTATE %in% c("oregon","Oregon","41",41)] <- 41
sdat$ST[sdat$SSTATE %in% c("pennsylvania","Pennsylvania","42",42)] <- 42
sdat$ST[sdat$SSTATE %in% c("rhode island","Rhode Island","44",44)] <- 44
sdat$ST[sdat$SSTATE %in% c("south carolina","South Carolina","45",45)] <- 45
sdat$ST[sdat$SSTATE %in% c("south dakota","South Dakota","46",46)] <- 46
sdat$ST[sdat$SSTATE %in% c("tennessee","Tennessee","47",47)] <- 47
sdat$ST[sdat$SSTATE %in% c("texas","Texas","48",48)] <- 48
sdat$ST[sdat$SSTATE %in% c("utah","Utah","49",49)] <- 49
sdat$ST[sdat$SSTATE %in% c("vermont","Vermont","50",50)] <- 50
sdat$ST[sdat$SSTATE %in% c("virginia","51","Virginia",51)] <- 51
sdat$ST[sdat$SSTATE %in% c("washington","Washington","53",53)] <- 53
sdat$ST[sdat$SSTATE %in% c("west virginia","West Virginia","54",54)] <- 54
sdat$ST[sdat$SSTATE %in% c("wisconsin","Wisconsin","55",55)] <- 55
sdat$ST[sdat$SSTATE %in% c("wyoming","Wyoming","56",56)] <- 56

## MEDICAID EXPANSION DATES
sdat$EXPANDED[sdat$ST==1 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==1 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==2] <- 0
sdat$EXPANDED[sdat$ST==2 & sdat$NUMBER >= 141] <- 1
sdat$EXPANDED[sdat$ST==4 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==4 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==5 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==5 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==6 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==6 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==8 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==8 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==9 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==9 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==10 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==10 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==11 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==11 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==12] <- 0
sdat$EXPANDED[sdat$ST==12 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==13] <- 0
sdat$EXPANDED[sdat$ST==13 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==15 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==15 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==16] <- 0
sdat$EXPANDED[sdat$ST==16 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==17 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==17 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==18 & sdat$NUMBER < 138] <- 0
sdat$EXPANDED[sdat$ST==18 & sdat$NUMBER > 137] <- 1
sdat$EXPANDED[sdat$ST==19 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==19 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==20] <- 0
sdat$EXPANDED[sdat$ST==20 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==21 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==21 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==22] <- 0
sdat$EXPANDED[sdat$ST==22 & sdat$NUMBER >= 153] <- 1
sdat$EXPANDED[sdat$ST==23] <- 0
sdat$EXPANDED[sdat$ST==23 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==24 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==24 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==25 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==25 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==26 & sdat$NUMBER < 129] <- 0
sdat$EXPANDED[sdat$ST==26 & sdat$NUMBER > 128] <- 1
sdat$EXPANDED[sdat$ST==27 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==27 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==28] <- 0
sdat$EXPANDED[sdat$ST==28 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==29] <- 0
sdat$EXPANDED[sdat$ST==29 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==30 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==30 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==31] <- 0
sdat$EXPANDED[sdat$ST==31 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==32 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==32 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==33 & sdat$NUMBER <= 132] <- 0
sdat$EXPANDED[sdat$ST==33 & sdat$NUMBER >= 134] <- 1
sdat$EXPANDED[sdat$ST==34 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==34 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==35 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==35 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==36 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==36 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==37] <- 0
sdat$EXPANDED[sdat$ST==37 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==38 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==38 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==39 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==39 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==40] <- 0
sdat$EXPANDED[sdat$ST==40 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==41 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==41 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==42 & sdat$NUMBER < 137] <- 0
sdat$EXPANDED[sdat$ST==42 & sdat$NUMBER > 136] <- 1
sdat$EXPANDED[sdat$ST==44 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==44 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==45] <- 0
sdat$EXPANDED[sdat$ST==45 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==46] <- 0
sdat$EXPANDED[sdat$ST==46 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==47] <- 0
sdat$EXPANDED[sdat$ST==47 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==48] <- 0
sdat$EXPANDED[sdat$ST==48 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==49] <- 0
sdat$EXPANDED[sdat$ST==49 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==50 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==50 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==51] <- 0
sdat$EXPANDED[sdat$ST==51 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==53 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==53 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==54 & sdat$NUMBER < 126] <- 0
sdat$EXPANDED[sdat$ST==54 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==55] <- 0
sdat$EXPANDED[sdat$ST==55 & sdat$NUMBER > 125] <- 1
sdat$EXPANDED[sdat$ST==56] <- 0
sdat$EXPANDED[sdat$ST==56 & sdat$NUMBER > 125] <- 1

sdat$ACAST[sdat$ST==1] <- 0
sdat$ACAST[sdat$ST==2] <- 1
sdat$ACAST[sdat$ST==4] <- 1
sdat$ACAST[sdat$ST==5] <- 1
sdat$ACAST[sdat$ST==6] <- 1
sdat$ACAST[sdat$ST==8] <- 1
sdat$ACAST[sdat$ST==9] <- 1
sdat$ACAST[sdat$ST==10] <- 1
sdat$ACAST[sdat$ST==11] <- 1
sdat$ACAST[sdat$ST==12] <- 0
sdat$ACAST[sdat$ST==13] <- 0
sdat$ACAST[sdat$ST==15] <- 1
sdat$ACAST[sdat$ST==16] <- 0
sdat$ACAST[sdat$ST==17] <- 1
sdat$ACAST[sdat$ST==18] <- 1
sdat$ACAST[sdat$ST==19] <- 1
sdat$ACAST[sdat$ST==20] <- 0
sdat$ACAST[sdat$ST==21] <- 1
sdat$ACAST[sdat$ST==22] <- 1
sdat$ACAST[sdat$ST==23] <- 0
sdat$ACAST[sdat$ST==24] <- 1
sdat$ACAST[sdat$ST==25] <- 1
sdat$ACAST[sdat$ST==26] <- 1
sdat$ACAST[sdat$ST==27] <- 1
sdat$ACAST[sdat$ST==28] <- 0
sdat$ACAST[sdat$ST==29] <- 0
sdat$ACAST[sdat$ST==30] <- 1
sdat$ACAST[sdat$ST==31] <- 0
sdat$ACAST[sdat$ST==32] <- 1
sdat$ACAST[sdat$ST==33] <- 1
sdat$ACAST[sdat$ST==34] <- 1
sdat$ACAST[sdat$ST==35] <- 1
sdat$ACAST[sdat$ST==36] <- 1
sdat$ACAST[sdat$ST==37] <- 0
sdat$ACAST[sdat$ST==38] <- 1
sdat$ACAST[sdat$ST==39] <- 1
sdat$ACAST[sdat$ST==40] <- 0
sdat$ACAST[sdat$ST==41] <- 1
sdat$ACAST[sdat$ST==42] <- 1
sdat$ACAST[sdat$ST==44] <- 1
sdat$ACAST[sdat$ST==45] <- 0
sdat$ACAST[sdat$ST==46] <- 0
sdat$ACAST[sdat$ST==47] <- 0
sdat$ACAST[sdat$ST==48] <- 0
sdat$ACAST[sdat$ST==49] <- 0
sdat$ACAST[sdat$ST==50] <- 1
sdat$ACAST[sdat$ST==51] <- 0
sdat$ACAST[sdat$ST==53] <- 1
sdat$ACAST[sdat$ST==54] <- 1
sdat$ACAST[sdat$ST==55] <- 0
sdat$ACAST[sdat$ST==56] <- 0

save(sdat,file="kffgeography/kff-joint-nogeo-12122018.Rdata",compress=T)




#sdat$AGECUT <- (sdat$AGE > 65)*1
#sdat$TIME <- (sdat$NUMBER - 82)
#sdat$AGENUM <- as.numeric(sdat$AGE)
#sdat$AGE2 <- (sdat$AGENUM-median(sdat$AGENUM,na.rm=T))/(max(sdat$AGENUM,na.rm=T)-min(sdat$AGENUM,na.rm=T))
#sdat$INCOME2 <- (sdat$INCOME-median(sdat$INCOME,na.rm=T))/(max(sdat$INCOME,na.rm=T)-min(sdat$INCOME,na.rm=T))
#sdat$MEDIEXPAND <- sdat$EXPANDED*sdat$ACAST
#sdat$DEM <- 1*(sdat$PID==1)
#sdat$GOP <- 1*(sdat$PID==3)
#sdat$UNCOVERED <- 1- sdat$COVERED
#sdat$AGESQ <- (sdat$AGE2*sdat$AGE2)/max(sdat$AGE2*sdat$AGE2,na.rm=T)
#sdat$AGE21 <- sdat$AGE2/max(sdat$AGE2,na.rm=T)
#sdat$INCOME3 <- sdat$INCOME/max(sdat$INCOME,na.rm=T)
#sdat$EDUC3 <- sdat$EDUC/max(sdat$EDUC,na.rm=T)

#save(sdat,file="0217.Rdata",compress=T)
